Sinfathisar
Registered User.
- Local time
- Today, 09:41
- Joined
- Jan 29, 2009
- Messages
- 60
So I had this code working and then I cleaned it up a little and it no longer works. It should export data from a created query using criteria selected by the user on a form and put it into an excel file that exists. I get no errors but it does not export anymore. After pouring over it for a while checking for mistakes with my form control references and variables I have yet to find anything. Any suggestions on what to look for or what might be missing? I did change my form name and edited the code accordingly after I already had it working, and changed a few form settings but changing them back did not fix the issue. I am not very experienced and stumped since I am not getting error messages.
Many thanks,
Many thanks,
Code:
'First set variables for the SQL string and CreateQueryDef command
Dim [COLOR=red]strExport[/COLOR] As String
Dim [COLOR=red]qdf[/COLOR] As dao.QueryDef
'Then define the SQL to be exported (Static Response Info by ItemID)
[COLOR=red]strExport [/COLOR]= "SELECT Static_Repeatability_Test_Table.[Static_Repeatability_ID], Static_Repeatability_Test_Table.[Static_Test_Item], Static_Repeatability_Test_Table.[Team_ID], Static_Repeatability_Test_Table.[Collection_Date], Seed_Test_Item_Table.[Static_Test_Item_Height], Static_Repeatability_Test_Table.[Static_Response_CH1], Static_Repeatability_Test_Table.[Static_Response_CH2], Static_Repeatability_Test_Table.[Static_Response_CH3], Static_Repeatability_Test_Table.[Static_Response_CH4], Seed_Test_Item_Table.[Response_Value_CH1], Seed_Test_Item_Table.[Response_Value_CH2], Seed_Test_Item_Table.[Response_Value_CH3], Seed_Test_Item_Table.[Response_Value_CH4], Static_Repeatability_Test_Table.[QCStatus_Ch1], Static_Repeatability_Test_Table.[QCStatus_Ch2], Static_Repeatability_Test_Table.[QCStatus_Ch3], Static_Repeatability_Test_Table.[QCStatus_Ch4] " & _
"FROM Static_Repeatability_Test_Table INNER JOIN Seed_Test_Item_Table ON Static_Repeatability_Test_Table.[Static_Test_Item] = Seed_Test_Item_Table.[Test_Item_ID] " & _
"WHERE [COLOR=red]Static_Repeatability_Test_Table.[Static_Test_Item] = Forms!Export_for_Excel_Chart_Static.SelectByItem [/COLOR]" & _
"ORDER BY Static_Repeatability_Test_Table.[Static_Test_Item], Static_Repeatability_Test_Table.[Team_ID], Static_Repeatability_Test_Table.[Collection_Date];"
'Create the query using SQL defined above
Set [COLOR=red]qdf[/COLOR] = CurrentDb.CreateQueryDef("[COLOR=red]Static_Response_Export_" & Forms!Export_for_Excel_Chart_Static!SelectByItem, strExport[/COLOR])
'Set variable for excel file to be exported into
Dim BookName As String
'Get the workbook name
[COLOR=red]BookName[/COLOR] = DLookup("[projectpath]", "[Project_Defaults]") & "\Grapher\" & "Static_Response_Chart.xlsx"
'Export querydef into specified .xlsx file
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "[COLOR=red]Static_Response_Export_" & Forms!Export_for_Excel_Chart_Static!SelectByItem[/COLOR], [COLOR=red]BookName[/COLOR], True
'Clean up the objects created with this function
[COLOR=red]qdf[/COLOR].Close
Set [COLOR=red]qdf[/COLOR] = Nothing
DoCmd.DeleteObject acQuery, "Static_Response_Export_" & Forms!Export_for_Excel_Chart_Static![COLOR=red]SelectByItem[/COLOR]