Alansidman
AWF VIP
- Local time
- Today, 13:56
- Joined
- Jul 31, 2008
- Messages
- 1,493
I am attempting to run a parameter query directly from Excel. There is only one parameter that is supplied in Cell D3 which is a date. The name of the database Excel is attempting to open is in Cell D4.
The code bombs out on the highlighted red line. It compiles with out issue. While the path shows here as a hyperlink, it is not in the code.
I get no error message, just a popup with a big red X
Any thoughts on this. What am I missing?
Running Excel 2010 and Access 2010 on Office XP.
Edit: I forgot to provide the error message when I run a Step through the code (F8)
Runtime 3343 Application-defined or object defined error.
:banghead:
The code bombs out on the highlighted red line. It compiles with out issue. While the path shows here as a hyperlink, it is not in the code.
I get no error message, just a popup with a big red X
Code:
Sub RunParameterQuery()
'Step 1: Declare your variables
Dim MyDatabase As DAO.Database
Dim MyQueryDef As DAO.QueryDef
Dim MyRecordset As DAO.Recordset
Dim MyPath As String
Dim MyDatabaseName As String
Dim i As Integer
MyPath = "[URL="file://\\officechihome7.office.adroot.bmogc.net\Userdata7$\asidman\home\CCDM"]\\officechihome7.office.adroot.bmogc.net\Userdata7$\asidman\home\CCDM[/URL] Prod DB files\"
MyDatabaseName = Range("D4").Value
'Step 2: Identify the database and query
[COLOR=red]Set MyDatabase = DBEngine.OpenDatabase(MyPath & MyDatabaseName)[/COLOR]
Set MyQueryDef = MyDatabase.QueryDefs("Query2")
'Step 3: Define the Parameters
With MyQueryDef
.Parameters("[Enter Date]") = Range("D3").Value
End With
'Step 4: Open the query
Set MyRecordset = MyQueryDef.OpenRecordset
'Step 5: Clear previous contents
Sheets("Main").Select
ActiveSheet.Range("A6:K10000").ClearContents
'Step 6: Copy the recordset to Excel
ActiveSheet.Range("A7").CopyFromRecordset MyRecordset
'Step 7: Add column heading names to the spreadsheet
For i = 1 To MyRecordset.Fields.Count
ActiveSheet.Cells(6, i).Value = MyRecordset.Fields(i - 1).Name
Next i
MsgBox "Your Query has been Run"
End Sub
Any thoughts on this. What am I missing?
Running Excel 2010 and Access 2010 on Office XP.
Edit: I forgot to provide the error message when I run a Step through the code (F8)
Runtime 3343 Application-defined or object defined error.

Last edited: