Results 1 to 6 of 6
  1. #1
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105

    compile error: expected end of statement


    how do you break up long lines of code over multiple lines?

    i thought it was just as simple as putting a _ at the end of the line

    strSQL = "SELECT tblBudgets.* " _
    "FROM tblBudgets " _
    "WHERE tblBudgets.FundID = '" & variableName & "';"

    if i put this all on one line, then it works fine. but when i try to break it up over several lines, then it turns red

    also, how do i turn off that annoying msgBox that pops up every single time. I can see that the text is red and something is wrong. I dont need a message box to tell me every single time.

  2. #2
    DaveT is offline Access Developer
    Windows 7 Access 2010 (version 14.0)
    Join Date
    May 2010
    Location
    Texas
    Posts
    69
    Looks like you need to add spaces such as " From tblBudgets" and " WHERE ...
    As to annoying red box, you might take a look at Tools, Options, Editor (in VBE) and clear the appropriate check box or boxes.
    As a minimum, I would keep Require Variable Declaration.

  3. #3
    DaveT is offline Access Developer
    Windows 7 Access 2010 (version 14.0)
    Join Date
    May 2010
    Location
    Texas
    Posts
    69
    Try this:

    strSQL = "SELECT tblBudgets.*" & _
    " FROM tblBudgets" & _
    " WHERE tblBudgets.FundID = '" & variableName & "';"

  4. #4
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    Thanks Dave.

    The example I posted was just something quick to explain what I'm talking about. I do have a space at the end of each line where there would be one if it was all on one line. But that doesn't seem to be the problem.

    is the _ underscore the correct character for breaking apart lines? And does it make a difference if it's a string or what type of variable it is?

  5. #5
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    I get an invalid character error when i put the & in

    EDIT: nevermind... i didn't realize there was a space between the & and the _

  6. #6
    DaveT is offline Access Developer
    Windows 7 Access 2010 (version 14.0)
    Join Date
    May 2010
    Location
    Texas
    Posts
    69
    Truth be known, I rarely use the underscore. To build embedded SQL I format it like this:

    mSQL = "SELECT ..."
    mSQL = mSQL & " FROM ..."
    mSQL = mSQL & " WHERE ..."

    It is forever and a day a hassle to get the variables quoted properly. Is it three or four quotes in a row, etc? I gave up and wrote a quote procedure:

    <CODE>
    Public Function RSQ(y As Variant) As String
    'short named version of ReturnSingleQuotedString
    'implementation from examples in Q147687
    'modified 2/27/2006 - DLT
    'return double quotes if null or zero len string passsed ("''""")
    Dim strY As String
    Const QuoteOne = "'"
    On Error GoTo TrapIt
    If IsNull(y) Then
    RSQ = "''"
    Exit Function

    ElseIf Len(y) = 0 Then
    RSQ = "''"
    Exit Function
    End If
    strY = CStr(y)
    If InStr(strY, QuoteOne) = 0 Then
    RSQ = QuoteOne & strY & QuoteOne
    Exit Function
    Else
    strY = ReplaceTheStr(strY, "'", "''")
    RSQ = QuoteOne & strY & QuoteOne
    Exit Function
    End If
    EnterHere:
    Exit Function
    TrapIt:
    RSQ = ""
    'remming out my std error reporting below
    'ReportErrVB Err.Number, "Error in RSQ procedure.", Err.Description
    Resume EnterHere
    End Function

    </CODE>

    So my code looks like:

    blah, blah "Where [myField] = " & RSQ(variable) & "....

    Dates are another beast, so I use:

    <CODE>

    Public Function RSQD(y As Variant) As String
    'return date criteria string
    'whole days, no time component
    'DLT Feb 22 2007
    On Error Resume Next
    RSQD = ""
    If Not IsDate(y) Then
    Exit Function
    Else
    RSQD = "#" & CStr(Format(y, "mm/dd/yyyy")) & "#"
    End If

    End Function

    </CODE>

    For numbers, especially integers, it's easy to go ahead and handle in the syntax such as:

    blah, blah, "WHERE [myID] = " & CStr(integer variable) & " ...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 07-21-2010, 02:41 AM
  2. Syntax Error while calling sub: Expected: =
    By cowboy in forum Programming
    Replies: 3
    Last Post: 07-12-2010, 02:21 PM
  3. Replies: 1
    Last Post: 04-24-2010, 09:57 AM
  4. Replies: 2
    Last Post: 12-03-2009, 05:06 PM
  5. Replies: 23
    Last Post: 03-26-2009, 06:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums