|
-
Jun 24th, 2004, 10:37 AM
#1
Thread Starter
Member
Dynamic Query list in Access
Hi All,
I am trying to find a method by which I can create an Access form that will list all of the queries that I have created. I then need the user to be able to select the query and run it.
Does anyone have any ideas, coz I haven't got a clue with this one!
Cheers
-
Jun 25th, 2004, 08:56 PM
#2
Try enumerating the QueryDefs colection excluding the system
and hidden queries, if any. Populate in a listbox or combo, or ???
On the click event of whatever object you use, DoCmd.OpenQuery or such.
HTH
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 
-
Jun 28th, 2004, 07:49 AM
#3
Thread Starter
Member
That sounds perfect! I am having problems with getting any queryDef stuff off the ground. When I run the code, VB doesn't know what a queryDef is. Does anyone know what I need to install or reference to get these working?
I have looked on MSDN but I cannot find anything that points me in the right direction.
Cheers
-
Jun 28th, 2004, 07:57 AM
#4
Thread Starter
Member
Found it!
Microsoft DAO 3.0 Object Library
-
Jun 28th, 2004, 08:17 AM
#5
Thread Starter
Member
OK, I have got my head around query defs, but I haven't found anything to do with a queryDef collection?
Can anyone point me in the direction of how to access the query def collection?
Cheers
-
Jun 28th, 2004, 09:11 AM
#6
Thread Starter
Member
OK, I can list the queries and put them in a combo box:
VB Code:
Public Function listQuery() As Boolean
Dim Arlen As Integer
Dim names() As String
Set Db = CurrentDb
If Db.QueryDefs.Count <> 0 Then
Arlen = Db.QueryDefs.Count
ReDim names(0 To Arlen - 1)
i = 0
For i = 0 To (Arlen) - 1
names(i) = Db.QueryDefs(i).name
Next i
End If
For i = 0 To (Arlen) - 1
If InStr(names(i), "Output") Then
cboQueryList.AddItem (names(i))
End If
Next i
End Function
Really easy question, but I just can't remember the answer.....how do you run a query?
-
Jun 28th, 2004, 09:28 AM
#7
Thread Starter
Member
If I try to execute the query using the method below, I get an error message saying that you cannot run a select query!
Any ideas?
VB Code:
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs(cboQueryList.Text)
qdf.Execute
qdf.Close
-
Jun 28th, 2004, 09:50 AM
#8
You know the name of the query, so in a display form (which opens up) set the datasource to the query name.
This should work for a list box or a full form. Your choice how you implement it.
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jun 28th, 2004, 10:01 AM
#9
Thread Starter
Member
Cheers for the idea Vince, but I have implemented a DoCmd...slightly nasty I know, but it needn't be anything too special.
Thanks for the tip though.
Does anyone know how to delete a query?
-
Jun 28th, 2004, 10:45 AM
#10
To drop an Access query using ADO...
VB Code:
sSQL = "DROP VIEW qryIDCount;"
Cnn.Execute sSQL
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
|