VBA ActiveX component can't create object

RIPLavabit

New Member
Joined
Aug 14, 2013
Messages
3
Code:
<code>
</code> Dim Data1 As String
    Dim Data2 As String
    Dim Data3 As String
    Dim Data4 As String
    
    
    'Using the AddNew method of the Recordset object
    Private Sub Method1()
        Dim adoRecordset As ADODB.Recordset
        Data1 = "hello"
        Data2 = "hello2"
        Data3 = "hello3"
        Data4 = "hello4"
        Set adoRecordset = New ADODB.Recordset
        With adoRecordset
            .Open "SELECT a,b,c,d FROM test", adoConnection, adOpenKeyset, adLockOptimistic
            .AddNew
            .Fields("a").Value = Data1
            .Fields("b").Value = Data2
            .Fields("c").Value = Data3
            .Fields("d").Value = Data4
            .Update
            .Close
        End With
        Set adoRecordset = Nothing
        MsgBox "Done using method1.   ", vbExclamation, "Recordset.AddNew"
    End Sub
    
    
    
    Private Sub add_Click()
        Method1
    End Sub

<code></code>
Code:
    Option Explicit
    
    Public adoConnection As ADODB.Connection
    
    Public Sub Main()
        Set adoConnection = New ADODB.Connection
        adoConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                      "Data Source= " & App.Path & "\dbAdd.mdb;"
        adoConnection.Open
        frmAdd.Show
    End Sub

Is there any fix for this, the debugger highlights this line
Code:
<code>adoConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _                                   "Data Source= " & App.Path & "\dbAdd.mdb;"
</code>
 
Last edited:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi,

It works for me. Be sure that app.Path is a valid path - you might be creating a bad string.

You can also try using the ACE provider (unless you are still using XP and Office 2003 you should have that).
 
Upvote 0
Hi,

It works for me. Be sure that app.Path is a valid path - you might be creating a bad string.

You can also try using the ACE provider (unless you are still using XP and Office 2003 you should have that).

yeah for some reason it was app.Path, i've just put the full directory name and now it works, thanks! :D

also what's the difference between ACE and Jet?
 
Upvote 0
Good. ACE is updated to work with accdb databases - the new db format that came out with Access 2007. It is also backward compatible with mdb's - either one is fine if you are connecting to an mdb.

ξ
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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