I have a DB that produces metrics for my group. The output is grouped by date. The collected metrics also contain a field called "Complete"..this could be Yes or No. I found some useful code to use in Excel to do this.
Sub Run_Access_Qry_Test()
'Step 1: Declare your variables
Dim MyDatabase As DAO.Database
Dim MyQueryDef As DAO.QueryDef
Dim MyRecordset As DAO.Recordset
Dim i As Integer
'Step 2: Identify the database and query
Set MyDatabase = DBEngine.OpenDatabase _
("\\nw\data\Maint_Train\MT Shared\John S\Bob K Project\Fleet Support\Fleet Support.mdb")
Set MyQueryDef = MyDatabase.QueryDefs("qry_Totals_Split_Non_ECM")
'Step 3: Define the Parameters
With MyQueryDef
.Parameters("[Enter:Yes, No, or Leave Blank]") = Range("D3").Value
End With
'Step 4: Open the query
Set MyRecordset = MyQueryDef.OpenRecordset
'Step 5: Clear previous contents
Sheets("Test").Select
ActiveSheet.Range("A6:K10000").ClearContents
'Step 6: Copy the recordset to Excel
ActiveSheet.Range("A7").CopyFromRecordset MyRecordset2
'Step 7: Add column heading names to the spreadsheet
For i = 1 To MyRecordset2.Fields.Count
ActiveSheet.Cells(6, i).Value = MyRecordset2.Fields(i - 1).Name
Next i
MsgBox "Your Query has been Run"
End Sub
This works...however. This parameter query only prepares the date for the final output query that groups the data by month. The output query gets its data from the parameter query. How can I run the output query right after the parameter query,so after step 4 above I need to run the output query ("\\nw\data\Maint_Train\MT Shared\John S\Bob K Project\Fleet Support\Fleet Support.mdb")
Set MyQueryDef2 = MyDatabase.QueryDefs("qry_Totals_Non_ECM Totals") returningthe results based on the parameter query?
Sorry if this is confusing but I need you to ask questions so I can get to the root of the issue.
Thanks in advance.
Sub Run_Access_Qry_Test()
'Step 1: Declare your variables
Dim MyDatabase As DAO.Database
Dim MyQueryDef As DAO.QueryDef
Dim MyRecordset As DAO.Recordset
Dim i As Integer
'Step 2: Identify the database and query
Set MyDatabase = DBEngine.OpenDatabase _
("\\nw\data\Maint_Train\MT Shared\John S\Bob K Project\Fleet Support\Fleet Support.mdb")
Set MyQueryDef = MyDatabase.QueryDefs("qry_Totals_Split_Non_ECM")
'Step 3: Define the Parameters
With MyQueryDef
.Parameters("[Enter:Yes, No, or Leave Blank]") = Range("D3").Value
End With
'Step 4: Open the query
Set MyRecordset = MyQueryDef.OpenRecordset
'Step 5: Clear previous contents
Sheets("Test").Select
ActiveSheet.Range("A6:K10000").ClearContents
'Step 6: Copy the recordset to Excel
ActiveSheet.Range("A7").CopyFromRecordset MyRecordset2
'Step 7: Add column heading names to the spreadsheet
For i = 1 To MyRecordset2.Fields.Count
ActiveSheet.Cells(6, i).Value = MyRecordset2.Fields(i - 1).Name
Next i
MsgBox "Your Query has been Run"
End Sub
This works...however. This parameter query only prepares the date for the final output query that groups the data by month. The output query gets its data from the parameter query. How can I run the output query right after the parameter query,so after step 4 above I need to run the output query ("\\nw\data\Maint_Train\MT Shared\John S\Bob K Project\Fleet Support\Fleet Support.mdb")
Set MyQueryDef2 = MyDatabase.QueryDefs("qry_Totals_Non_ECM Totals") returningthe results based on the parameter query?
Sorry if this is confusing but I need you to ask questions so I can get to the root of the issue.
Thanks in advance.