Solved

Code not working

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
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 stored procedures 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 Micr…

914 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

19 Experts available now in Live!

Get 1:1 Help Now