Results 1 to 3 of 3

Thread: SQL (97)

  1. #1
    Lounger
    Join Date
    Jul 2003
    Location
    Dublin, Ireland, Republic of
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SQL (97)

    I'm writing a line of SQL, declaring a variable and setting it equal to the SQL code. The line is too long to fit on one line and has to carry on to the next, I keep getting an Error:expected end of statement compile error. Would this be due to the fact that the SQL is going on to the next line, and if it is, does anyone know a way to fix it. Thanks,
    Triona

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: SQL (97)

    If a statement is too long to fit on one line, you can use the underscore _ to distribute it over multiple lines:

    DoCmd.OpenForm FormName:="frmFormWithARatherLongName", _
    WindowMode:=acDialog

    There must be a space before the underscore. If you use this method to break up a long string, you must enclose each part in quotes, and use & to indicate that the parts must be concatenated into one long string:

    strSQL = "SELECT Field1, Field2, Field3 " & _
    "FROM tblSomething " & _
    "WHERE Field1 > 0 And Field2 Is Not Null"

    If you break up a string like this, remember to put in spaces where needed (in this example after Field3 and tblSomething).

  3. #3
    Lounger
    Join Date
    Jul 2003
    Location
    Dublin, Ireland, Republic of
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SQL (97)

    That fixed it, thanks Hans!

Posting Permissions

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