I have some VBA code that pushes a query out to Excel. It works fine on my machine with Windows XP and Access 2003 but not on my managers machine which has Windows 2000 and Access 2000 (don't ask me why the interns machine is brand new and the managers is 3+ years old). Here is the code I have:
Private Sub cmd_Excel_Push_Click()
Dim strPath As String
Dim ExcelFile As Object
strPath = Environ("temp") & "\shipper_" & Format(Now, "dddd_mmmm_dd_yyyy_hh_mm_ss") & ".xls"
MsgBox ("This excel file will be saved to your temp directory. Please resave it to another location.")
'MsgBox strPath
Select Case strTable
Case Is = "Shipper"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_excel_shipper", strPath
Case Is = "Comp"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_excel_comp", strPath
Case Is = "Both"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_excel_both", strPath
End Select
Call Shell("Excel " & strPath, vbMaximizedFocus)
End Sub
The error message I get says "Cannot find C:\Documents" and then "Cannot find and". It seems like it cannot find the temp folder but I thought Environ can be used in 2K and XP.
As of right now I am the only one that has Access 2003 but I would like it to work with both versions.
Private Sub cmd_Excel_Push_Click()
Dim strPath As String
Dim ExcelFile As Object
strPath = Environ("temp") & "\shipper_" & Format(Now, "dddd_mmmm_dd_yyyy_hh_mm_ss") & ".xls"
MsgBox ("This excel file will be saved to your temp directory. Please resave it to another location.")
'MsgBox strPath
Select Case strTable
Case Is = "Shipper"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_excel_shipper", strPath
Case Is = "Comp"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_excel_comp", strPath
Case Is = "Both"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_excel_both", strPath
End Select
Call Shell("Excel " & strPath, vbMaximizedFocus)
End Sub
The error message I get says "Cannot find C:\Documents" and then "Cannot find and". It seems like it cannot find the temp folder but I thought Environ can be used in 2K and XP.
As of right now I am the only one that has Access 2003 but I would like it to work with both versions.