We help IT Professionals succeed at work.

update a table from a form

Medium Priority
319 Views
Last Modified: 2012-05-12
I have a form that is based on a table called survey. The table has several fields the one I need to update are surveyID and date.I need to update the table while the form is open. I 'm trying to use the INSERT TO stmt

Dim letterdate As String

letterdate = Date
 

CurrentDb.Execute "INSERT INTO survey (SurveyID,date)" & _
" Values (1, 'letterdate')"

If I just do the surveyID it works great. But if I add the date to the statement I get a syntax error. I have tried different editing combs but no luck.

Any help would be helpful.  

Thanks
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
CurrentDb.Execute "INSERT INTO survey (SurveyID,date)" & _
" Values (1, #" & letterdate & "#)"

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
You should also Dim letterdate as a date, assuming your field is date type and not text:

Dim letterdate As Date
letterdate = Date
CurrentDb.Execute "INSERT INTO survey (SurveyID,date)" & _
" Values (1, #" & letterdate & "#)", dbfailonerror




Author

Commented:
Hi Mbizup, pasted the code in and still getting a syntax error???
CERTIFIED EXPERT
Top Expert 2016
Commented:
slight revision, Date is  a reserved word. enclose in []

CurrentDb.Execute "INSERT INTO survey (SurveyID,[date])" & _
" Values (1, #" & letterdate & "#)", dbfailonerror

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013
Commented:
Are the field and table names correct?
Is your Date field of date type, or is it actually text in the table's design?

If date is the actual field name, try using square brackets like this (or rename the field, as it is a 'reserved word')

Dim LetterDate As Date
LetterDate = Date()
CurrentDb.Execute "INSERT INTO survey (SurveyID,[date]) Values (1, #" & LetterDate & "#)", dbFailOnError

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.