i want to open a recordset, in its 'where' clause i want to pass the value which i entered in Form textbox? is this possible ?
COde:
rs.open "select * from table1 where id=form.textbox",con
i have written general code above.
when i run my application ..it gives error "Control which is focus can only be reference"
how can i pass my value to select query ?
I am trying to run this recordset with parameter query and export to excel. Problem I am getting is it is sending the ID of employee name and exporting row wise instead of column wise.
Code: Dim dbMyDatabase As DAO.Database Dim rsMyRecords1 As DAO.Recordset Dim qdMyParameters1 As DAO.QueryDef Dim iIndex As Integer Dim iFound As Integer Dim oExcel As New Excel.Application
I want to be able to have multiple parameter queries, but the user needs to have the option of entering a parameter or not limiting the output at all. How do I let the user choose "all", or what do they type in so that nothing is excluded?
Hi, I need help in creating a parameterized query.
I need to show only certain fields depending on the value of the parameters. For example, I have a table with fields: ID, Name, Phone Number, Address, DOB. The parameter can only be value of A, B or C. If the user input A as the parameter in the query, only field ID, and Name will be shown If the user input B as the parameter in the query, field ID, Name and Phone Number will be shown. etc.
Is there any way to do this, rather than to separate the query into 3 queries for each of the parameters? Thank you.
I have form with a button on it that launches a parameter-based Select query (which served as the source for a report). I didn't have any validation measure in place, so if the User supplied a bogus value, a blank report was generated. While not technically an error, it would seem more polished to generate a warning message if the User supplies a bad query value and prompt them to re-enter.
Having read other posts along these lines, I've added an unbound text box to the form which the User fills in first before clicking the button. When the button is clicked, it executes code that uses the DCount function to make sure the text box value is in the source table, and if it is then it runs the parameter-based Select query. My question is how to pass the value in the text box to the query as a parameter. Below is a sanitized version of the code that I've generated so far.
Private Sub SingleItemRptB_Click() If DCount("[FieldName]", "[Table]", "[FieldName]=[TextBoxValue]") = 0 Then MsgBox "Item not in database. Please check value and re-enter." Else DoCmd.OpenQuery "SingleItemQ", acViewNormal, acReadOnly End If End Sub
I created a form that has 3 multiple drop-down selections that is supposed to select records from [TableName_1] based on those selections. I initially created the query using the query designer with actual "hard coded" selections to make sure it worked. When it gave me the expected records, I changed the criteria from the "hard coded" option to the input form's control reference [Forms]![FormName]![ComboName]. I did this one at a time and tested after each change.
After the first change, I got exactly what I expected.
After the second change, it seemed okay. (note: I put the criteria on the first criteria line in the query designer, not on the second line)
After the third change, I get the dreaded: The expression is typed incorrectly or is too complex to be evaluated....
Here is the SQL:
SELECT M_Lending_Institution.InstitutionName, M_Lending_Institution.GeoRegionID, M_Lending_Institution.SpecialtyID, M_Lending_Institution.SBA FROM (SELECT M_Lending_Institution.InstitutionName, M_Lending_Institution.GeoRegionID, M_Lending_Institution.SpecialtyID, M_Lending_Institution.SBA FROM M_Lending_Institution) AS LenderSearchQuery WHERE (((LenderSearchQuery.GeoRegionID.Value)=[Forms]![LoanSearch]![CmbPrefGeo]) AND ((LenderSearchQuery.SpecialtyID)=[Forms]![LoanSearch]![CmbSpecialtyArea]) AND ((LenderSearchQuery.SBA)=[Forms]![LoanSearch]![CmbSBA]));
And once this is sorted out, yes I want to be able to allow for all records to be returned if any of those fields is NULL. I've read a LOT of posts around this subject, but I can't seem to find anything that answers my question without jumping into advanced VBA code.
I have a query with multiple fields that is being run off of 3 parameters (linked for selection in a form). The problem is, I wanted to enable a select all feature, so I included a "Or ... Is Null" part in my criteria section, so that when nothing is selected, the query/report returns all records.
Okay so the problem is whenever I run the query with nothing selected for the parameter and then return to design view for the query, a new field has been created in the query design, titled with the expression I use to pull the parameter value from the form. This is frustrating because then that is causing errors in another report I run that pulls values from that query.
Basically, I have a database table that is maintained every week. It is about e-mail account licenses for Office 365.
Each column represents a week of license data for every mailbox account which is about 10 000 plus users with the date as the field headers( something like "License information as of 06122013").
Basically, I have created 52 queries based on the license type I require to be calculated & I have a form created to control it. However, right now it is all output only as I have yet to create any user parameter to specify on any of the queries about the date I want
As I am currently unsure how to specify all the queries to use one field date header which I want the user to specify via drop down list in order to calculate all the licenses on this specific date.
For example, if I want to see the license information for 06/11/2013, I would choose "License as of 06112013" & it would then run all the queries based on the header specified earlier & output that information on the form.
Right now the queries are all configured as the "Select" type.
I'm trying to the following sub to automate the creation of RecordSets but I'm confuse how to get it done properly.
Public Sub OpenRecordSet(SQLString As String, NameRecordset As Object) Set NameRecordset = New ADODB.Recordset NameRecordset.Open SQLString, adOpenStatic, adLockOptimistic
I want to pass the name of the recordset as a parameter but I don't know how to set it.
Set TRANS1 = db.OpenRecordset("SELECT * FROM MASTER WHERE DatePart("yyyy", TRANS1![CDATE]) = " & 2014, dbOpenDynaset)
In the above recordset selection, the ACCESS seems do not allow to have the DATEPART("YYYY") function in the syntax. As CDATE is a table field with date/time data type. Just want to know, how to do this kind of date selection. My purpose is to select all records according to a specific date to the TRANS1 recordset.
Trying to use a form based on a table to choose a recordset of values, and pick the ID of that recordset to include in another table as a foreign key.
I am not sure how to even search for what I'm trying to do, though I've tried all the variants I can think of anyway.
The idea being that there are a set of values that are associated with each other, and generally found in conjunction with another set of data. So Table 1 contains data such as this, though this is greatly simplified from the numerics that are actually stored in these fields:
FooID Field 1 Field 2 Field 3 etc, etc... 1 x y z 2 d y z 3 x y q 4 x r P . . .
This data is then associated with the information in table 2, and rather than repeat fields 1-whatever in table 2 I want to use the FooID in table 2 to store the link to all of the subsequent field data. Normalization as I understand it in other words.
I cannot figure out how to pull the table 1 data into a datasheet form and allow someone to choose one of the lines of data, store the FooID into an unbound text box, or some other method, and then run an update query on table 2 to update a field with the FooID for the 12-72 records that are in that table.
Would this make more sense as a combo box in a single form? I've been trying to do this with a datasheet, but I think I'm too limited in appending a check box to an individual recordset this way, or at least I've not managed to get it to work so far anyway.
I have a database with lists clients across the UK. I have now been asked to provide options where users can select clients grouped by geopraphical area e.g say clients in Scotland.
I can of course do this but having numerous identical forms where the source queries have different parameters depending on the regions required.
The only problem with this is that I would need numerous forms and queries. Additionally, there are options on the form to navigate to linked forms which would all need to be unique.
What I would like to have options on my main (Switchboard Type) Introduction Form to select the region. The code on the relevent command button would include the parameter. I would therefore not require the additional forms.
The open form codes includes:
Dim stDocName As String Dim stLinkCriteria As String
I feel i need something after "frmClients" such as qryClients.ClientArea = "Not Scotland". Various attempts to incorporate something has created errors.
I am creating an absenteeism database which has the following tables:
tblEmp - PK - auto number, EmpId, First Name, Last name tblFunction - PK - FID (autonumber) has departments tblTL - PK TLID (autonumber) has list of team leaders tblRelated - pK - Id (auto), EmpId, TLID, FId as long integeres tblCodes - CodeId (auto), list of absenteeism codes like late, mia, etc EmpLeave - pk - autonumber, empid, codeid, hours, date of absenteeism
I have a Qry_Master which just joins all the information together as it gets updated on a monthly basis
Now, I am trying to create a form where the user has option to select one or more tls and one or more codes and when they hit the button, it should come up with all emps that have those codes and report to the team leader selected.
In my form, I have made both my list boxes as multiselect and i have Qry_frm that is a parameter query but when i run the button nothing happens and i cant seem to figure it out. I have attached the sample database to this thread.
I have a form whose data source is a select query, q3, that is built from 2 other select queries. I'll call them q1, q2, and q3. q1 is a parameter query where I enter a "Cutoff Date" that the 3 queries manipulte and generate the desired results that appear in the form. The problem is that I don't know how to capture the parameter "Cutoff Date" from q1 to display on the form.
Special situation: The SQL Server Linked Server across the country is linked to a Read Only Oracle DB. This data pull works perfectly and populates the Subform.
The problem is that Oracle can take 3 to 6 seconds to retrieve the single record depending on the network traffic through a small pipe.
The code below shows the RecordSource for the SubForm. clicking on a list box supplies the value. Then 3 to 6 seconds later, the subform populates.
The actual Recordset for this Recordsource is needed to conduct Validation on each field. Normally this would be on SQL Server, I might just create a Recordset Oject and run this SQL statement again in 1 milisecond. In this case, it will probably take an additional 3 to 6 seconds. Avoiding another lengthy round-trip to Oracle would be prefered.
Goal: How does one grab, clone, or other wise reference the existing recordset for the SubForm?
Note: Immediate Window - One single field can be returned quickly
There are 48 fields that need validation - is there a way to reference the entire recordset?
Immediate Window during Break Mode: ? me.fsubsrNavSHLBHL("NavSH_QQ") NESE ' this is the correct value for the current recordsource
Set a breakpoint right after the line: fsubsrNavSHLBHL.Form.RecordSource = "Select * from vsrNavigatorSHLBHL where Well_ID =" & txtNavWellID.Value
Immediate Window: ? me.fsubsrNavSHLBHL.Form.RecordSource Select * from vsrNavigatorSHLBHL where Well_ID =91229
I have a query that requires a Start-Date and an End-Date to be input by user for the Where clause. It is asking for both over and over. I've had it ask from 1 up to 4 times! :eek: Shouldn't it store the input and only ask for it once? I'm thinking that the way my query is arranged may be causing it to have to loop through that section more than once to find the data, but that's just my theory. Any help would be great!
Here is my code (abbreviated slightly):
SELECT DISTINCTROW C1.*, C2.* FROM Pen AS C1 INNER JOIN Jobs AS C2 ON C1.subno=C2.[Jobs Acct] WHERE ((C1.typ="SS" Or C1.typ="CC" Or C1.typ="PP" Or C1.typ="TT") And C1.stdate>=[Enter Start Date] And C1.stdate<=[Enter End Date] And C2.[Type]<>"EE" And C2.[Type]<>"QQ" And C1.entdate<=C2.[ChangeDate]+60);
I'm selecting rows from "Pen" and "Jobs" that have the same subno/Jobs Acct numbers (text), then there are criteria for "Pen" types, user inputs criteria for date range (Start Date and End Date) and there are criteria for "Jobs" types. Finally, there's a cross-table criteria based on a date field ("Pen" entdate should not be more than 60 days past the "Jobs" ChangeDate). Tables are in quotes in my explanation here.
So running the above, it asks for user input "Enter Start Date", then again for "Enter End Date"...but then it asks for each again...and again...and sometimes again!
Help! :confused:
P.S..I didn't notice this repeating until I made it user input (parameter query) because it was using whatever dates I hard-coded in there before.
Hi...hope someone can help. I'm a bit new to the programming scene and need some help with a recordset.
The current code that I am using is:
Private Sub Command126_Click() 'September - 2006 - Create Application Form. Dim appWord As Word.Application Dim NoPrompt Dim rstContacts As Recordset Set rstContacts = Me.Recordset
Set appWord = GetObject(, "Word.Application")
With appWord .Documents.Add "C:Documents and SettingsAdministratorMy Documents est.doc" .ActiveDocument.ShowSpellingErrors = False .Selection.Goto wdGoToBookmark, Name:="test" End With
Do Until rstContacts.EOF
appWord.Selection.TypeText rstContacts!ContactName & " " rstContacts.MoveNext Loop End Sub
I want a situation where recordset information can be 'fed' to a word document depending on what is written in control boxes on the form. So, for example if there are three options in a Combo Box, namely:
Option 1, Option 2 and Option 3
I want information from the 'ContactName' control box to be inserted in the 'test' document at specific 'bookmarks' for all forms where 'Option 1' is selected in the Combo Box.
Hope this makes sense....I think I'm getting close but still no joy
Hi, I know MS Access quite but not much. I am using Access 2000.
What I want to do is to use DLOOKUP Function to find a value stored in a recordset defined in VBA. I successfully did this task by creating a query.
You will say if I have done this then what is the problem. Dear I have to create as many queries as NO of forms as this query is required on every form on a controll when it is double clicked. Thus I want to create a function with my parameter which is "Date" of that form.
For testing I created this sub on my form but got an error .
Error message says ****Run Time Error '3061' ****Too Few parameters. Expected 1
I really am not able to get why this error is coming as I copied and pasted this SqlString created by MSAccess from my successful query .
================================== Dim rstTemp As Recordset Dim sqlStr As String
sqlStr = "SELECT tblJournal.Account AS AccID, Sum(tblJournal.amtDebit) AS Dr, Sum(tblJournal.amtCredit) AS Cr, tblCOA.OpBalDr, tblCOA.OpBalCr, [OpBalDr]+[Dr] AS Debit, [Cr]+[OpBalCr] AS Credit, [Debit]-[Credit] AS Bal FROM tblCOA INNER JOIN tblJournal ON tblCOA.accNum = tblJournal.Account WHERE (((tblJournal.Date) <= " & Me.Date & " )) GROUP BY tblJournal.Account, tblCOA.OpBalDr, tblCOA.OpBalCr;"
Set rstTemp = CurrentDb.OpenRecordset(sqlStr)
xx = DLookup("[Bal]", "rstTemp", "AccID=1010")
MsgBox xx
rstTemp.Close
================================ Please tell where I am wrong and how can I perform this task in a rather easier way.
Hi guys, I'm a bit confused: I know that opening a bound form will bring down the whole recordset. But if I create a parametered query as the recordsource, will it still bring down the whole recordset first and only afterwards cut down to the records matching the parameters?
Example: I have a clients table with 5000 clients on a backend mdb, and my client lookup form in my frontend mdb. If I open the form looking for just client "Jim Jones" (via the parameter query), will Access bring down all 5000 clients from the backend to my frontend first, and only then seek out "Jim Jones" before discarding the rest of the recordset?
For if this is true then this whole Access business is rather unsuited for networks, even a small one. I hope you guys prove me wrong.
I want to write a email where there are 2 or 3 different ordernumbers for same email, i want to include the email in the mail part as single column table. how to do it? also can i use result of one recordset for other recordset?
I have a database in which the tables are located in one MS Access file, and the queries, forms, reports, etc. are all located in a seperate MS Access file (MS Access 2003). The MS Access file that stores the tables, I call the "back end file".
I got a call regarding the database, and found that some how the back-end file got corrupted. When I want to open the file, I got the error...
"Database is not in a recognized format.... You must repair the file".
So I clicked "Yes" to compact and repair the back-end file, and the database worked correctly for me.
All except one query. I have a query that pulls in the main table of the database and then one of the subform queries. Linked on the main table primary key, it is a pretty simple query. This query has always been used to update data for the sub-form.
Today, after the compact and repair job, this query became a locked record set. I cannot add, edit or delete from the records in this query.
I can add, edit and delete from both the tables in the query, just not from the query itself. To make things even more strange, when I try to edit, I don't get the message at the bottom of the query stating "This recordset is locked".
I am just wondering if anyone has experienced this, and if there is something more trouble some brewing. If so, is there anyway to fix my query? Is my database back end file still corrupt (I have compact and repaired it since then). I even copied every table from the back-end file into a new MS Access database file, and I still get the same error with the query.
I've been banging my head against this problem for a while now and making no progress and am hoping someone cleverer than me can provide some assistance in solving it, or point me in the right direction.
Here goes....
I am working solely in the VBA environment and would like to perform an automated process that returns a recordset based on the results of a previously created recordset (assuming of course it is possible in the first instance.)
The catch is I would like to perform an INNER JOIN using the results held within a recordset. I have already achieved this by creating a temporary table (using a SELECT INTO statement) and then removing the temporary table when I am finished but find this is a slower process than I would like.
I have three tables: Table A - Fields: GROUP, NAME, DATA1, DATA2 Table B - Fields: GROUP, NAME, , CITY, DATA3 Table C - Fields: CITY, DATA3
I have the following declarations:
Dim db As Database Dim rs1 As Recordset, rs2 As Recordset, rs3 As Recordset Dim strSql As String
Set db = CurrentDb
Next, I select a specific range I am interested in. For the purpose of this example, I am only selecting GROUP values of 1,2 and 3.
strSql = "SELECT * FROM A WHERE A.GROUP IN (1,2,3)" Set rs1 = db.OpenRecordset(strSql) rs1.MoveFirst
Now, for each record returned in the query above, I would like to process as follows:
The rs2 query returns the results of that query into what I though was a memory resident table referred to as "jc". (This is most likely where I am going wrong!) Using this reference, I perform another query...
And from this point I would be able to process the results (if any) that I need to....
...if it wasn't for the error: "The Microsoft Jet database engine cannot find the input table or query 'jc'. Make sure it exists and that its name is spelled correctly."
I know the table doesn't 'truly' exist as a physical object or entity within the database, so how do I reference this 'phantom' table in a query?
I am happy to provide more details if it would help solve this problem and would really appreciate any feedback that anyone has to offer.
I am in the middle of creating a function that populates two unbound text boxes on a form and then uses those unbound textboxes in a query (Total of 3 unbound text boxes - 2 are populated from this function). The saved query object is working fine when I manually execute it (after the unbound text boxes have been populated). However, when I go to set the same query to a recordset I am getting the "Too Few Parameters. Expected 3." error message.
In the saved query I used the build function to use the unbound text boxes as part of the where clause. Below is the code I am trying to execute:
PHP Code:
Public Function Test()Dim db As DAO.DatabaseSet db = CurrentDbDim rst As DAO.Recordset Dim DtBegin As String''FInd the Begin dtstBegin = DateAdd("q", -1, DateSerial(Year(Date), (DatePart("q", Date) - 1) * 3 + 1, 1)) Dim DtEnd As String''find the end dateDtEnd = DateAdd("Q", DateDiff("Q", 0, Date) - 1, 0)
[Code] ......
The unbound text boxes are populated before the query is set to the recordset.
I'm trying to assign the result of an SQL query to a variable using VBA in Access. The query returns a value but the variable which it is assigned to has a value of Nothing. Here is the code snippet:
Dim queryReturnID As String queryReturnID = "select dbo_tbl_SupplierReturn.ReturnID from dbo_tbl_SupplierReturn" & _ " where SupplierID = " & lstPOHdr.Column(1) Debug.Print queryReturnID Dim RecordSet1 As DAO.RecordSet Set RecordSet1 = CurrentDb.OpenRecordset(queryReturnID)