So I’m currently trying to convert a foxpro .dbf table from an mrp system my company uses (PCMRP) to an excel spreadsheet via my Access application using ADO and an ODBC connection. I’m getting the following error: Could not find file “C:userstempPartMast.mdb”. See code below. In no way am i referencing PartMast.mdb in my code. When debugging, the docmd.transferspreadsheet line is where it is getting tripped up. I think it has to do with the tempQueryforExport because when the code stops at the docmd.transferspreadsheet line, the query shows up in the Access Objects in the left pane. When i try to run that query it gives the same error. Any ideas on why this is happening/ how to fix this?
Private Sub Command1_Click()
Dim strconnect As String
Dim cn As ADODB.Connection
Dim dbfFolder As String
Dim rs As ADODB.Recordset
Dim SQL As String
Set cn = New ADODB.Connection
Dim tempqueryname As String
Dim db As Database
Dim qdf As QueryDef
tempqueryname = "tmpQueryforExport"
dbfFolder = "C:UserstburelltempPC MRP"
strconnect = "DSN=pcMRPVFP;SourceDB=u:PC MRP;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;"
filename = "PARTMAST.dbf"
Set cn = New ADODB.Connection
cn.Open strconnect
cn.Execute "SET REPROCESS TO 10 SECONDS"
Set rs = New ADODB.Recordset
SQL = "SELECT * from PartMast.dbf order by partno;"
rs.Open SQL, cn
Set db = CurrentDb
Set qdf = db.CreateQueryDef(tempqueryname)
qdf.SQL = SQL
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, tempqueryname, dbfFolder & "" & Left(filename, 8) & ".xls", 1
rs.Close
Set rs = Nothing
Set cn = Nothing
db.QueryDefs.Delete tempqueryname
Set qdf = Nothing
Set db = Nothing
End Sub