Syntax error

swmorin

Registered User.
Local time
Yesterday, 20:08
Joined
Jan 10, 2012
Messages
66
This is really staring to anger me. I can't seem to get the syntax correct for this query.

Code:
CurrentDb.Execute ("UPDATE tbl_courses" & _
"SET tbl_courses.COURSENUM =[Forms]![frm_createcourse_edit]![Text7]" & _
"WHERE tbl_courses.COURSEID)=[Forms]![frm_createcourse_edit]![Courseid];")
 
You need to expose those textbox references:
Code:
CurrentDb.Execute "UPDATE tbl_courses" & _
                  "SET COURSENUM = " & [Forms]![frm_createcourse_edit]![Text7] & " " & _
                  "WHERE COURSEID = " & [Forms]![frm_createcourse_edit]![Courseid] & ";")
If CourseNum or CourseID are String types you will need to wrap them in single quotes.
 
Still not working here is the exact code from my db.
Code:
CurrentDb.Execute ("UPDATE tbl_courses" & _
"SET tbl_courses.COURSENUM = " & [Forms]![frm_createcourse_edit]![Text7] & " " & _
"WHERE tbl_courses.COURSEID = " & [Forms]![frm_createcourse_edit]![courseid] & ";")
 
What does "still not working" actually mean? Any errors? Does it not update any tables? Do you have error handling in place?
 
Syntax error still.

Sorry about the misunderstanding
 
Remove the outer brackets and try again. And as vbaInet asked
If CourseNum or CourseID are String types you will need to wrap them in single quotes.
 
tbl_courses.COURSENUM is a text field
tbl_courses.COURSEID is an auto number primary key

Is this what you mean?
 
Ok! So it should be this:
Code:
CurrentDb.Execute "UPDATE tbl_courses" & _
                  "SET COURSENUM = [COLOR=Red]'[/COLOR]" & [Forms]![frm_createcourse_edit]![Text7] & "[COLOR=Red]'[/COLOR] " & _
                  "WHERE COURSEID = " & [Forms]![frm_createcourse_edit]![Courseid] & ";"
Single quotes surround Text values.
 
Still getting the syntax error in UPDATE statement

Code:
CurrentDb.Execute ("UPDATE tbl_courses" & _
"SET tbl_courses.COURSENUM = '" & [Forms]![frm_createcourse_edit]![Text7] & "' " & _
"WHERE tbl_courses.COURSEID = " & [Forms]![frm_createcourse_edit]![courseid] & ";")
 
Space after tbl_Courses. Final verison:
Code:
CurrentDb.Execute "UPDATE tbl_course[COLOR=Red]s "[/COLOR] & _
                  "SET COURSENUM = '" & [Forms]![frm_createcourse_edit]![Text7] & "' " & _
                  "WHERE COURSEID = " & [Forms]![frm_createcourse_edit]![Courseid] & ";"
You don't need the parentheses.
 
That Worked thanks.

One more question. Do date/time fields require single quotes?
 
so it would look like this

#" & [form]![DateField] & "#
 
That's right!

But don't forget the proper reference to the control or field

#" & [Forms]![frm_createcourse_edit]![DateField] & "#
 
Damnit now I am getting a missing operator error.

Code:
CurrentDb.Execute ("UPDATE tbl_courses " & _
"SET tbl_courses.COURSENUM = '" & [Forms]![frm_createcourse_edit]![Text7] & "' " & _
"tbl_courses.COURSEDATE = #" & [Forms]![frm_createcourse_edit]![Text3] & "# " & _
"tbl_courses.COURSETITLE = '" & [Forms]![frm_createcourse_edit]![Text1] & "' " & _
"tbl_courses.COURSEBLOCKS = " & [Forms]![frm_createcourse_edit]![Text5] & " " & _
"tbl_courses.COURSEDAYS = " & [Forms]![frm_createcourse_edit]![Text9] & " " & _
"tbl_courses.COURSEHOURS = " & [Forms]![frm_createcourse_edit]![Text11] & " " & _
"WHERE tbl_courses.COURSEID = " & [Forms]![frm_createcourse_edit]![courseid] & ";")
 
You need to separate the fields with a comma
General format

Update Table
Set fld1 = Value1
, fld2 = value2
, fld3 = value3.......
 

Users who are viewing this thread

Back
Top Bottom