Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Insert Not working, Can you spot why

Posted on 2014-02-19
3
Medium Priority
?
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1000 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 48

Expert Comment

by:Dale Fye
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

715 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