Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Mar 2003
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help With SQL statement (Access2K)

    Can anyone help me with this SQL syntax?

    strSQL = "INSERT INTO tblFromCMISMasterRecord ( MasterRecordID, SSN, FirstName, MiddleInitial, LastName, AddressLine1, AddressLine2, ZipCodeID, PhoneNumber, DOB, Age, Sex, CaseManagerID, ChangeDate )"
    strSQL = strSQL & " SELECT tblMasterRecord.MasterRecordID, Format([PIN],"000-00-0000") AS SSN, tblMasterRecord.FirstName, tblMasterRecord.MiddleInitial, tblMasterRecord.LastName, tblMasterRecord.AddressLine1, tblMasterRecord.AddressLine2, tblMasterRecord.ZipCodeID, tblMasterRecord.PhoneNumber, tblMasterRecord.DOB, tblMasterRecord.Age, tblMasterRecord.Sex, tblMasterRecord.CaseManagerID, tblMasterRecord.ChangeDate "
    strSQL = strSQL & " FROM tblMasterRecord;"

    Access doesn't like the part about FORMAT([PIN], "000-00-0000") AS SSN in my SQL statement when I try to run in from code.

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

    Re: Help With SQL statement (Access2K)

    This is because the quotes in the Format statement make VBA think the SQL string ends there. To include quotes within a quoted string, you must double them:

    strSQL = strSQL & " SELECT tblMasterRecord.MasterRecordID, Format([PIN],""000-00-0000"") AS SSN, ...

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Help With SQL statement (Access2K)

    As Hans pointed out, it is the double-quotes within double-quotes that is causing you problems. An alternative to using double, double quotes is to use single quotes around the items that are embedded within double-quotes. So your string would start like this:

    strSQL = strSQL & " SELECT tblMasterRecord.MasterRecordID, Format([PIN],'000-00-0000') AS SSN......etc....."
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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