Consulting

Results 1 to 3 of 3

Thread: VBA syntax error

  1. #1

    VBA syntax error

    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

  2. #2
    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.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    VBAX Tutor
    Joined
    Mar 2014
    Posts
    210
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •