How Do I Query A Recordset Object In VBA?
Aug 15, 2006
Hi all,
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:
' // Build SQL statement
strSql = ""
strSql = strSql & "SELECT B.* "
strSql = strSql & "AS jc "
strSql = strSql & "FROM A "
strSql = strSql & "INNER JOIN B ON (A.Id = B.Id) "
strSql = strSql & "WHERE B.Name = " & rs1.Fields("Name")
strSql = strSql & " And A.Name = B.Name"
Set rs2 = db.OpenRecordset(strSql)
rs2.MoveFirst
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...
' // Build SQL statement
strSql = ""
strSql = strSql & "SELECT * FROM jc "
strSql = strSql & "INNER JOIN [C] ON (jc.City = C.City) "
strSql = strSql & "WHERE (([jc]![City] In ([jc]![City]) ))"
Set rs3 = db.OpenRecordset(strSql)
rs3.MoveFirst
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.
Thanks,
JC
View Replies
ADVERTISEMENT
Oct 14, 2013
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.
View 5 Replies
View Related
Aug 14, 2015
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
View 4 Replies
View Related
Feb 6, 2013
My form respectively subform has a couple of problems related to the recordset as it is available in VBA.
The mainform contains material data, the subform contains the components of that material and a quantity, while the components are materials themselves. The subform's control source is an SQL statement created by the query builder.
Everything worked fine before i replaced the material-selecting combobox in the continuous subform by a textbox and a button. That button leads to another (dialog) form with some filtering options, which in turn returns the number of the selected material. This material gets inserted into the textbox. To this point it works fine.
But when i enter a quantity before i selected a Material, i get an error message after selecting the Material: This Action was Cancelled by an Associated Object. This happens while executing the following VBA Code on click of the material selection button (exact position commented in code):
Code:
Private Sub cbuSelectComponent_Click()
' Select component
Dim SQL As String
Dim rs As Recordset
DoCmd.OpenForm "Material Selector Dialog", , , , , acDialog, "Dialog"
If GLB_selected_mat = -1 Then 'cancel
[Code] ....
I've found the following Microsoft KB Article: [URL] ..... In their example code they use:
' Restore text box value to the original record contents
' in this case, that is NULL
datDataCtl.UpdateControls
I assume this is the relevant part, but i have no DataControl (what's that?) and neither found an UpdateControls method in the subform object.
The second error, "no current recordset", occures when i edit an existing component line in the subform that has been added right before (also using the same event and code as mentioned above). If i close the form after adding the component and open it again, it's no problem.
View 2 Replies
View Related
Jul 8, 2015
Which reference to be added to use Recordset object in Excel VBA. I added "Microsoft DAO 3.6 Object Library" reference but still its not working.
View 8 Replies
View Related
Jun 9, 2005
Hello
I am using Access 2003(11.6355.6360) SPI
When I attempt to create a new DB - by performing Blank Database I immediately get a message 'Object Library not registered'.
If I 'OK' that box and try to create a table, I can do so - create Table in design view.
When I then try to Import external data - an excel file I get the message 'ActiveX component Can't create object'.
I have looked ob various sites for help and forum information regarding these errors but have found nothing conclusive, with specidfic regard to Access 2003.
The version has been loaded on my machine about 1 year as part pf Office Professional but this is the first time I have attempted to run Access itself.
Does any forum member have any ideas as to how this problem could be resolved.
Thank You
Rgds
Paul Langham
View 1 Replies
View Related
Jan 5, 2015
I am currently building a database for the company I work for that is fairly similar to the Northwind Database; however it is made from scratch so hopefully some of the common problems with that database won't find their way into mine.My problem is that when I go to my Orders form, I pick a customer from the main form, which creates a record on the Orders table. When I then go to the subform to choose a product/line item, I get the error in my title ("The LinkMasterFields property setting has produced this error: 'The object doesn't contain the Automation object 'OrdersT.") as soon as a product is chosen from the drop down list.
View 1 Replies
View Related
Jul 17, 2013
The error is:
The LinkMasterFields property setting has produced this error: 'The object doesn't contain the Automation object 'tblIndividual.' '
Then it also gives me the same one on another table.
I think it has something to do with the link master/child fields. I've tried all kinds of relationships with the three tables and can't figure it out.
I've tried uploading the database here but it won't. It's on my Sky Drive.
[URL] .....
View 5 Replies
View Related
Dec 27, 2006
I'm getting an error message (informational only):
The object doesn't contain the automation object 'ClientID.'You tried to run a visual basic procedure to set a property or method for an object. However, the component doesn't make the property or method available for Automation operations.
Check the components documentation for information on the properties and methods it makes available for automation operations.
This happens when I start entering data in the field "productname" of a subform.
So I'm assuming something in the form or in the code of the form is referring to ClientID. but I've checked it, and there is nothing referring to it anymore. Well, at least as far as I'm aware of.
This afternoon access crashed without any error, it just closed. Upon reopening the DB again, all my work of the past one and a half week was gone. Normally I always backup the data, but these past days I didn't due to christmas and still working a lot too. So I forgot.
I did some redesigning in the process this evening, deleting and adding some fields and code.
I can't get rid of this error. Can anyone help? Or point me in the right direction?
Also the DB is 3.5MB in size. While it is completely empty. And I can't imagine that some empty tables, queries, forms and a bit of code can be so much. But that's for a later time to worry about I guess, unless one of you says: this and that, maybe that works... Otherwise, I would really be very glad already if the error disappears....
View 3 Replies
View Related
Sep 19, 2006
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
Thanks
Chris
View 5 Replies
View Related
Aug 16, 2007
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.
Thanks and your help is greatly appriciated.
View 1 Replies
View Related
Sep 9, 2005
Hi,
I have some queries in a list. When I run one of them I would like to show result on form. I made a subform and I defined from code in runtime the actually selected query as the subform's source object. It didn't work. :(
Why? How could I show a query's results on a form?
If somebody could help me , I would be very grateful!
View 2 Replies
View Related
Apr 27, 2007
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.
Premy
View 14 Replies
View Related
Jul 7, 2013
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?
View 1 Replies
View Related
May 11, 2007
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.
Very strange, and sort of a worry.
Let me know, and thank you for your time.
T.J.
View 4 Replies
View Related
Jun 6, 2005
Hi again,
I now have the ability to select a query and have a form open on that record set.
The problem is that some of the queries generate the error message : Invalid SQL statement; expected 'DELETE',INSERT','PROCEDURE','SELECT' or 'UPDATE'
Code is
Private Sub Combo0_Click()
sQuery = Combo0.Column(0)
DoCmd.OpenForm "frmFilter"
Set rstSuppliers = New ADODB.Recordset
rstSuppliers.CursorLocation = adUseClient
rstSuppliers.Open sQuery, CurrentProject.Connection
Set Forms("frmFilter").Recordset = rstSuppliers
Forms("frmFilter").UniqueTable = sQuery
End Sub
THe queries are the same type. :confused:
View 5 Replies
View Related
Oct 1, 2004
I am creating an form in a database and whenever one of my procedure's run it creates this error message:
The expression ON Load you entered as the event property setting produced the following error:
Member already exists in an object module from which this object module derives.
*The expression may not result in the name of a macro, the name of a user-defined function, or [event Procedure].
*There may have been an error evaluating the function, event, or macro.
An ideas?
View 7 Replies
View Related
Jun 25, 2005
hi ,
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 ?
thanks
View 2 Replies
View Related
Jun 11, 2014
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)
View 3 Replies
View Related
Dec 15, 2014
I want to use Recordset to work with query but get the error "Run-time error '3061' too less parameters. Expected one".
Code:
Dim rst As Recordset
Dim strSQL As String
Dim krojenie As String
strSQL = "SELECT * FROM powtorzeniaDoKrojenia"
[Code] .....
View 3 Replies
View Related
Aug 14, 2013
Code:
Private Sub Command37_Click()
Dim db As DAO.Database
Dim rsItems As DAO.Recordset
Dim SQL As String
Dim currentItemNumber As Long
[code]....
adding record set in report and displaying a report..i want every record to pass thru recodset and create a report for every record separately
View 1 Replies
View Related
Feb 6, 2015
The following code supposed to let me print all records OR only those where dAreaFK = myCBO currently I get an error message "Object missing".if i remove this: Or Me!cboStatsArea Is Null..from the last line the it works but only if i make selection in combo.
Code:
Private Sub cmdPrintOpen_Click()
'Print open defects using R_Open_details
Dim i As Integer
i = DCount("*", "Q_Open_details", "dAreaFK=cboStatsArea OR cboStatsArea IS Null")
'MsgBox "The count of rows is " & i
If i = 0 Then
MsgBox "No Records available for print", _
vbOKOnly, "Error"
Exit Sub
End If
DoCmd.OpenReport "R_Open_details", acPreview, , _
"dAreaFK=" & Me!cboStatsArea Or Me!cboStatsArea Is Null
End Sub
View 6 Replies
View Related
Jul 10, 2013
I am trying to create an update query. I am trying to update a field in a table with the current date as a request.
I have a table named tblTest and a field named Date2 that I am trying to update with the current date, the button that the VBA is applied to is in a form name frmTest. This is my code:
Private Sub Command39_Click()
Dim t1 As Date
t1 = Date
db.Execute("update tblTest set tblTest.Date2") = t1
End Sub
But when I press the button I get:
Run time error '424'
Object Required
It highlights the 4th of code....
View 8 Replies
View Related
Feb 2, 2006
Hi there,
I have to queries as below
one which shows a few stats figures etc all on a single row but has 6 columns altogether
the other shows some figures by function area and as there are like 7 function areas there are 7 rows but only 2 columns
i want all this informaiton onto one report so i guess that i need to merge this data together onto the one query some how
whats the best way to do this?
thanks
View 2 Replies
View Related
Sep 6, 2006
Can someone tell me the VBA code for testing whether a query recordset is empty or not?
View 1 Replies
View Related
Mar 5, 2015
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
[Code] ....
View 3 Replies
View Related