Solved

Code not working

Posted on 2014-03-28
3
222 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
  • 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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

860 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