I'm thinking you're gonna have to do something like:
Using code, loop through all the queries in the access database and return them to a dropdown box so the user can pick one to use
For this, you will need to have set your references.
sheet1 will get the returned data
Sheet2 should have a combobox called cbQueries (from the controls toolbox)
paste these into a standard module:
Sub GetQueries()
Dim dbs As Database
Set wks = DBEngine.CreateWorkspace("", "admin", "", dbUseJet)
Set dbs = wks.OpenDatabase("c:\Home\Access\GB_Universe.mdb", True) Sheets("Sheet2"

.cbQueries.Clear
For Each qdf In dbs.querydefs
Sheets("Sheet2"

.cbQueries.AddItem (qdf.Name)
Next
dbs.Close
Set dbs = Nothing
End Sub
Sub execute()
Dim dbs As Database, rst As Recordset, wks As Workspace, ws As Worksheet
Dim sQuery As String
sQuery = Sheets("Sheet2"

.cbQueries.Text
Set wks = DBEngine.CreateWorkspace("", "admin", "", dbUseJet)
Set dbs = wks.OpenDatabase("c:\Home\Access\GB_Universe.mdb", True)
Set rst = dbs.OpenRecordset(sQuery)
'If Err.Number < 0 Then GoTo ErrorExit
Set ws = Worksheets("sheet1"

With ws
.Activate
.Cells.ClearContents
For iCol = 1 To rst.Fields.Count
.Cells(1, iCol).Value = rst.Fields(iCol - 1).Name
Next
.Cells(1, 1).CurrentRegion.Font.Bold = True
.Cells(2, 1).CopyFromRecordset rst
End With
'End If
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
wks.Close
Set wks = Nothing
Set ws = Nothing
Exit Sub
ErrorExit:
' error trapping...
End Sub
Run "GetQueries" - this will populate the combobox with a list of all the queries currently saved in the database
Once a query has ben selected, run "Execute" to return the data to sheet1
Rgds, Geoff
Quantum materiae materietur marmota monax si marmota monax materiam possit materiari?
Want the
best answers to your questions ? faq222-2244