Solved

Code not working

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

744 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

13 Experts available now in Live!

Get 1:1 Help Now