• Help With SQL statement (Access2K)

    Author
    Topic
    #423103

    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.

    Viewing 1 reply thread
    Author
    Replies
    • #967083

      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, …

    • #967169

      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…..”

    Viewing 1 reply thread
    Reply To: Help With SQL statement (Access2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: