?
Solved

Code not working

Posted on 2014-03-28
3
Medium Priority
?
236 Views
Last Modified: 2014-03-28
I am trying to use the below code to save values entered into an unbound field named txtZipCodeEntered. The table to save it to is tblZipCodeHistory in the column ZipEntered and the next column, TimeStamp, is the a time stamp of when it was entered.

After everything I have tried, including making a new form with just the unbound field and button, shows the attached error. Then highlights the line. Any idea of how to fix it?

Private Sub Command3_Click()
Dim Statement As String

Statement = "INSERT INTO tblZipCodeHistory (ZipEntered, TimeStamp ) VALUES ( '{0}', {1} ); "
Statement = Replace(Statement, "{0}", txtZipEntered.Value)
Statement = Replace(Statement, "{1}", Format(Now, "\#m\/d\/yyyy hh\:nn\:ss\#"))
MsgBox Statement
CurrentDb.Execute Statement, dbFailOnError Or dbSeeChanges

End Sub

Open in new window

Screen-shot-4.pdf
0
Comment
Question by:cansevin
[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
  • 2
3 Comments
 

Author Comment

by:cansevin
ID: 39962051
I must be doing something wrong with the code. I just attached a new database with just the form and table. Same issue comes up. See attached. Any idea what I'm doing wrong?
Database1.accdb
0
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 39962096
You need to enclose the field name 'TimeStamp' in square brackets.  It seems to be a reserved word which is causing the error:

Statement = "INSERT INTO tblZipCodeHistory (ZipEntered, [TimeStamp] ) VALUES ( '{0}', {1} ); "

Open in new window

0
 

Author Closing Comment

by:cansevin
ID: 39962204
Yes!!!!!!!!!!!!!!! Made my day, thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…
Suggested Courses

752 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