Link to home
Start Free TrialLog in
Avatar of mlcktmguy
mlcktmguyFlag for United States of America

asked on

Insert Not working, Can you spot why

I just created the following insert statement in my application.  I have many others just like it, except for differnet tables.  It compiles cleanly, I verified that all of the fields have valid data in them.  The numerics have numbers, the dates have dates and the strings have strings.

I verified that the command executes, no errors or warnings are thrown.  However, it doesn't add a new record to the specified table.

Here is the statement:

    CurrentDb.Execute " insert into  tblProperty_PhoneNumbers " & _
                  "( [PropertyID], [BRT], [PhoneNum], [PhoneNum_JustNum], [DialerStatusID], [DateNumberEntered], [DatePhoneStatusUpdated], [DateAdded], [UserAdded] " & _
      "   values(" & passedPropertyID & _
              ", " & passedBRT & _
              ", " & Chr(34) & passedPhoneNum & Chr(34) & _
              ", " & wkJustPhoneNum & _
              ", " & passedCallResultID & _
              ", " & Chr(35) & wkDateAdded & Chr(35) & _
              ", " & Chr(35) & wkDateAdded & Chr(35) & _
              ", " & Chr(35) & wkDateAdded & Chr(35) & _
              ", " & Chr(34) & wkUserAdded & Chr(34) & _
              ")"

Open in new window


I use the chr(35) for # and chr(34) for ".  I do this many places in my app also, including on other insert statements.

Can any one spot an issue?
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mlcktmguy

ASKER

Bingo, thanks
You might benefit from my Wrap function:
Public Function Wrap(WrapWhat as Variant, _
                     Optional WrapWith as String = """") as String

    If IsNull(WrapWhat) then WrapWhat = "NULL"

   Wrap = WrapWith _
        & Replace(WrapWhat, WrapWith, WrapWith & WrapWith) & WrapWith

End Function

Open in new window

Then, in your code you would write:

strSQL = "insert into  tblProperty_PhoneNumbers " _
        & "([PropertyID], [BRT], [PhoneNum], [PhoneNum_JustNum], " _
        & "[DialerStatusID], [DateNumberEntered], [DatePhoneStatusUpdated], " _
        & "[DateAdded], [UserAdded]) " _
        & "Values(" & passedPropertyID _
             & ", " & passedBRT _
             & ", " & WRAP(passedPhoneNum) _
             & ", " & wkJustPhoneNum _
             & ", " & passedCallResultID _
             & ", " & Wrap(wkDateAdded, "#") _
             & ", " & Wrap(wkDateAdded, "#") _
             & ", " & Wrap(wkDateAdded, "#") _
             & ", " & Wrap(wkUserAdded) _
             & ")" 
Currentdb.Execute strSQL, dbFailonError

Open in new window