G
Guest
I am using Access 2003 and VBA (SQL SERVER 2000 backend) to create a table .
However when I try to access it to save its contents as a CSV file, it says
Run-Time error '7874': can't find the object table
HOWEVER, if I manually reconnect to the server (File --> Connection), the
table is there, and AFTER this reconnection, the code can find the table and
do the export etc. properly.
To enact the above in code, I added code to close the connection, reconnect,
and refresh the database window. It still gives me the above error. Please
help if you can.
Here is the code:
' To create the table
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.Open "Provider = sqloledb.1; data source = myPC; intial catalog = myDB;
integrated security = sspi"
cn.Execute "exec myDB.dbo.spmySP '" & strBatchDone & "' "
' Server = myPC; database = myDB; stored proc to create table = spmySP
' To close, reconnect and to refresh database window
cn.close
cn.Open "Provider = sqloledb.1; data source = myPC; intial catalog = myDB;
integrated security = sspi"
RefreshDatabaseWindow
' To export a CSV file based on myTable, created using the stored proc above
DoCmd.TransferText acExportDelim, , "myTable", "c:\temp\" strBatchDone &
".csv", -1
Please note that the syntax etc is correct as the above works fine when I go
step by step manually. In code, the last line (DoCmd.Transfer......) gives
the run-time '7874' eror, saying Myable can't be found, even though it is
created and does exist.
TIA
j-d
However when I try to access it to save its contents as a CSV file, it says
Run-Time error '7874': can't find the object table
HOWEVER, if I manually reconnect to the server (File --> Connection), the
table is there, and AFTER this reconnection, the code can find the table and
do the export etc. properly.
To enact the above in code, I added code to close the connection, reconnect,
and refresh the database window. It still gives me the above error. Please
help if you can.
Here is the code:
' To create the table
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.Open "Provider = sqloledb.1; data source = myPC; intial catalog = myDB;
integrated security = sspi"
cn.Execute "exec myDB.dbo.spmySP '" & strBatchDone & "' "
' Server = myPC; database = myDB; stored proc to create table = spmySP
' To close, reconnect and to refresh database window
cn.close
cn.Open "Provider = sqloledb.1; data source = myPC; intial catalog = myDB;
integrated security = sspi"
RefreshDatabaseWindow
' To export a CSV file based on myTable, created using the stored proc above
DoCmd.TransferText acExportDelim, , "myTable", "c:\temp\" strBatchDone &
".csv", -1
Please note that the syntax etc is correct as the above works fine when I go
step by step manually. In code, the last line (DoCmd.Transfer......) gives
the run-time '7874' eror, saying Myable can't be found, even though it is
created and does exist.
TIA
j-d