Results 1 to 4 of 4
  1. #1
    Wayne311 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    91

    SQL that errors in VB

    I have this code:



    Code:
     
    DoCmd.RunCommand acCmdSelectRecord
    intRcptNumber = (Form!RcptNumber)
    DoCmd.SetWarnings False
     
    strSQL = "SELECT RcptData.[RcptNumber] AS [RcptData_RcptNumber], RcptData.[DateReceived], RcptData.[CarrierLName], RcptData.[CarrierFName], RcptData.[CarrierMName], RcptData.[AmountPaid], RcptData.[Check#], RcptData.[Clerk], RcptData.[Mail/OverCounter], RcptData.[Memo], RcptCRDistrict.[RcptNumber] AS [RcptCRDistrict_RcptNumber], RcptCRDistrict.[CRNumber], RcptCRDistrict.[District], RcptCRDistrict.[Charge], RcptCRDistrict.[N/C] INTO PrintReceiptTemp" & _
    "FROM RcptData INNER JOIN RcptCRDistrict ON RcptData.[RcptNumber] = RcptCRDistrict.[RcptNumber]" & _
    "WHERE (((RcptData.[RcptNumber]) = intRcptNumber));"
     
    DoCmd.RunSQL strSQL
    The SQL works in a Query but with VB I get an error. (See attached)

    Any ideas what is wrong?

    Thanks
    Wayne

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    When building SQL in VBA, you have to make sure to include a space when using line continuations. You're going to end up with this type of thing:

    ...INTO PrintReceiptTempFROM...

    Note the lack of a space between the table name and FROM.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Wayne311 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    91
    Good eye!

    Thanks that did it.

    Wayne

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem Wayne!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 10
    Last Post: 07-25-2011, 12:07 PM
  2. #Name? errors with textboxes
    By jasonbarnes in forum Forms
    Replies: 3
    Last Post: 12-16-2010, 09:51 AM
  3. How do I display SQL constraint errors?
    By isabelle2378 in forum Forms
    Replies: 3
    Last Post: 10-19-2010, 03:23 PM
  4. .ocx Files Errors
    By darshita in forum Import/Export Data
    Replies: 9
    Last Post: 12-07-2009, 07:36 AM
  5. Replies: 1
    Last Post: 03-11-2006, 07:38 AM

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