Vba compile syntax error on ADODB Connection - SOLVED

I would like to compile the following vba code, but I get a syntax error (source position 2,20) on the word “.Connection” on the following:

Public Sub ConnectDB(db As String)
Set Cnn = New ADODB.Connection 'errors here
Cnn.ConnectionString = “DRIVER={MySQL ODBC 5.3 Unicode Driver};SERVER=s555; _
DATABASE=” & db & “;USER=u555;PASSWORD=p555;Option=3”
If Not Cnn.State = adStateOpen Then Debug.Print “No Connection”

Any suggestions? Thanks!

The VBA compiler doesn’t know what ADODB is. To access Excel objects in our VBA compiler, add the Application. prefix (with the dot) as outlined in the user guide.

For instance, the following code lets you create a database connection:

Thank you!

Just as a reference for others who may spend a very long time trying to reference objects created from compiled vba, can you please post a link to the user guide?

And also just for clarification, I did not see the Application prefix in the attached screenshot. This may seem kind of confusing.

Thanks again!

For the record, I did see your example on another post and was able to compile the code like your recommendation…

Set Conn = CreateObject(“ADODB.Connection”)


The user guide in PDF format is shipped with XLS Padlock and is displayed when you click the Help buttons in the software.
We also published it online on our website: https://www.xlspadlock.com/doc/XLSPadlock-Guide.pdf
For the Application. prefix, this is better explained at paragraph 7.4 in the guide: Accessing Excel objects from compiled VBA code


Thank you!