Microsoft Jet 4.0

Kurt

Well-known Member
Joined
Jul 23, 2002
Messages
1,664
Hello Everyone,

I have the following code:

Code:
Sub command_parameters()
    Dim conn As New Connection
    Dim rec As New Recordset
    Dim comm As Command
    Dim ws As Worksheet
    Dim countryname$
    Set ws = ThisWorkbook.Worksheets("command")
    conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
        "Data Source=" + ThisWorkbook.Path + "C:\NWind.mbd;"
    Set comm.ActiveConnection = conn
    comm.CommandText = _
        "SELECT companyname FROM Customers WHERE Country = ?"
    countryname = InputBox("Please input the name of a country " & _
        "(for example, 'germany').")
    rec.Open comm
    ws.[a1].CopyFromRecordset rec
    rec.Close: conn.Close
End Sub

I have VBA For Applications, Microsoft Excel 11.0 Object Library, OLE Automation, Microsoft Active X Data Objects 2.5 Library check in Tools, References. The Active X Data Objects 2.5 Library should reference Jet 4.0. My code keeps stoping on this line:

Code:
conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
        "Data Source=" + ThisWorkbook.Path + "C:\NWind.mbd;"

What am I forgetting here? I had it working in another spreadsheet with the same references. The worksheet is not protected.

TIA

Kurt
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
ThisWorkbook.Path + "C:\NWind.mbd"

will return sometrhing thast can't be resolved

do you mean
ThisWorkbook.Path & "\NWind.mbd"?
 
Upvote 0
concantenation

Hello,

I tried replacing the + with a & and still no luck.

Code:
    conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
        "Data Source=" + ThisWorkbook.Path + "\nwind.mbd;"

I now get a error message run time error: some number.

Any other thoughts. Thanks for your efforts.

Kurt
 
Upvote 0
concantenation

Hello All,

Fixed it!

I got past the jet statement then bombed on the rec.Open comm line and realized I left the line out above it.

Regis this is the final answer!

Code:
Sub command_parameters()
    Dim conn As New Connection
    Dim rec As New Recordset
    Dim comm As New Command
    Dim ws As Worksheet
    Dim countryname$
    Set ws = ThisWorkbook.Worksheets("command")
    conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
        "Data Source=" + ThisWorkbook.Path + "\nwind.mdb;"
    Set comm.ActiveConnection = conn
    comm.CommandText = _
        "SELECT companyname FROM Customers WHERE Country = ?"
    countryname = InputBox("Please input the name of a country " & _
        "(for example, 'germany').")
    comm.Parameters(0) = countryname
    rec.Open comm
    ws.[a1].CopyFromRecordset rec
    rec.Close: conn.Close
End Sub

Thanks again for those who replied!

Have a great and product day!

Kurt
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top