0

I am trying to connect to Mysql via VBA in access. I have created my DSN on my computer, the test connection works well. In VBA I am doing this :

Dim S As String
    Set oConnect = New ADODB.Connection
    S = "DRIVER={MySQL ODBC 5.3 ANSI Driver};" & _
        "SERVER=localhost ;" & _
        "DATABASE=myDataBase ;" & _
        "USER=root;" & _
        "PASSWORD=root;" & _
        "Option=3"
    oConnect.Open S

I am getting this error :

Defined type by user is not defined.

I have referenced Microsoft Activex Data object 2.8.

Thanks.

3
  • Is Microsoft AtiveX Data Objects 2.x Library activated ? Commented Aug 10, 2015 at 7:37
  • 1
    Change USER for uid and PASSWORD for pwd Commented Aug 10, 2015 at 7:39
  • 1
    Do you have some code around this? Because you only define a string here and the error message can't be on this one as it is a predefined type. +1 for @Hearner comment Commented Aug 10, 2015 at 7:45

1 Answer 1

1

The right way is :

Driver={mysql};  & _
database=nameDB; & _
server=NameServer; & _
uid=NameUser; & _
pwd=PassWord; & _
option=16386;

Change USER for uid and PASSWORD for pwd

And don't forget to active the library : Microsoft AtiveX Data Objects 2.x Library.

Change your S to :

 S = "DRIVER={MySQL ODBC 5.3 ANSI Driver};" & _
     "SERVER=localhost ;" & _
     "DATABASE=myDataBase ;" & _
     "uid=root;" & _
         "pwd=root;" & _
         "Option=3;"
oConnect.ConnectionString  S
oConnect.Open
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.