PDA

View Full Version : VBA syntax error



dmikester1
10-03-2014, 08:54 AM
This is probably very simple, but I have very little experience in VBA coding.
I am getting a syntax error, and it highlights the second line. Any ideas why?

Dim oConn As ADODB.Connection

Private Sub ConnectDB()

Set oConn = New ADODB.Connection

oConn.Open "DRIVER={MySQL ODBC 5.1 Driver};" & _

"SERVER=xxx;" & _

"DATABASE=xxx;" & _

"USER=xxx;" & _

"PASSWORD=xxx;" & _

"Option=3"

End Sub

Jan Karel Pieterse
10-03-2014, 10:48 AM
The line has a so-called line continuation character at the end (the underscore), indicating that the line of code continues on the next line. But the next line is empty. If you remove the empty lines in-between, all should be well.

ranman256
10-03-2014, 10:48 AM
If you mean :Private Sub ConnectDB()
then it should have told you why in the error.
It could be the PRIVATE. Change to PUBLIC ...since I dont know the error message.