|
-
Mar 3rd, 2005, 01:24 PM
#1
Thread Starter
Frenzied Member
Setting recordset to query in Access VBA [Solved]
hey I am trying to set a recordset to a query in my database so I can use the .findfirst function. I keep getting a error saying that the item is not found in the collection.
Is this possible or do I have to use a table instead of a query for my recordset?
the code I am using is:
VB Code:
Dim rcQuery1 as Recordset
Set rcQuery1 = Recordset("Query1")
I am getting stuck on the set statement.
Thanks for any help.
Last edited by Besoup; Mar 3rd, 2005 at 02:21 PM.
-
Mar 3rd, 2005, 01:52 PM
#2
Junior Member
Re: Setting recordset to query in Access VBA
Hi....
the easiest way to do this is to refer the Microsoft DAO 3.6 Object Library (if you use at least Acess 2000) and work with the DAO objects.
VB Code:
Dim db As DAO.DataBase
Dim rs as DAO.Recordset
Set db = CurrentDB()
Set rs = db.OpenRecordSet("Query1")
While Not rs.Eof
' Do what has to be done ;-)
rs.MoveNext
Wend
Set rs = Nothing
if you only want to execute the query:
VB Code:
Dim rs As ADODB.Recordset
Set rs = CurrentProject.Connection.Execute("select * from Query1")
While Not rs.Eof
' Do what has to be done ;-)
rs.MoveNext
Wend
Set rs = Nothing
Last edited by ivobenkovic; Mar 3rd, 2005 at 01:59 PM.
-
Mar 3rd, 2005, 01:57 PM
#3
Thread Starter
Frenzied Member
Re: Setting recordset to query in Access VBA
Ty
-
Mar 3rd, 2005, 02:02 PM
#4
Thread Starter
Frenzied Member
Re: Setting recordset to query in Access VBA [UnSolved]
Actually I thought that was gonna work but now I am getting a too few parameters error with the following code:
VB Code:
Dim db As DAO.DataBase
Dim rs as DAO.Recordset
Set db = CurrentDB()
Set rs = db.OpenRecordSet("Query1")
-
Mar 3rd, 2005, 02:21 PM
#5
Thread Starter
Frenzied Member
Re: Setting recordset to query in Access VBA [UnSolved]
Got it now.... me dumb. Thanks for the help.
-
Mar 3rd, 2005, 02:27 PM
#6
Re: Setting recordset to query in Access VBA [UnSolved]
The OpenRecordSet method takes parameters in addition to the query.
VB Code:
Private Sub OpenMe()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("Query1", dbOpenDynamic, dbReadOnly, dbOptimistic)
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|