Solved

Code not working

Posted on 2014-03-28
3
223 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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

679 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