Why The DB Must Be Open????

S

SIN

Hi,
when i run that pro and the DB close I get Error: 2075
"this operation requires an open database"
when i open the data base is work.

The code:

Private Sub Command1_Click()

Dim cn As ADODB.Connection
Dim sPath As String
Set cn = New ADODB.Connection
cn.Open "DSN=TEST1"
sPath = "D:\ImportCurrencyRate.xls"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Temp_Rates",
sPath, True
End

thanks.
 
6

'69 Camaro

Why The DB Must Be Open?
when i run that pro and the DB close I get Error: 2075
"this operation requires an open database"
when i open the data base is work.

When one connects to a database, it's like making a phone call to another
person. The other person needs to be there to answer your phone call in
order for you to "connect" and start talking to each other. Likewise, the
database must be open and ready to receive connections ("phone calls") from
other applications before they can start talking to one another.

Your code doesn't open the database prior to the ADO connection attempt.
Hence, no one is there to accept the phone call, so there can be no two-way
communication. Open the database first, and your application will be able
to connect and "talk" to it.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
S

Scott McDaniel

Hi,
when i run that pro and the DB close I get Error: 2075
"this operation requires an open database"
when i open the data base is work.

Actually, I think the code is failing on the DoCmd.TransferSpreadsheet statement ... IIRC, this requires that the
database you specify be open. You can connect to an Access/Jet database whether Access has it open or not.
The code:

Private Sub Command1_Click()

Dim cn As ADODB.Connection
Dim sPath As String
Set cn = New ADODB.Connection
cn.Open "DSN=TEST1"
sPath = "D:\ImportCurrencyRate.xls"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Temp_Rates",
sPath, True
End

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
S

SIN

thanks,
i try to find example to import excel file - without definition (rang) -
automat
and i didnt find any.
now i know that i need recordset,,, but how???
thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top