Solved

Insert Not working, Can you spot why

Posted on 2014-02-19
3
269 Views
Last Modified: 2014-02-19
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?
0
Comment
Question by:mlcktmguy
3 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
ID: 39871349
you are missing a closing paren ")" before  "values"


    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) & _
              ")"
0
 
LVL 1

Author Closing Comment

by:mlcktmguy
ID: 39871525
Bingo, thanks
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39871755
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

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now