Using a variable as a field name

echorley

Registered User.
Local time
Today, 17:07
Joined
Mar 11, 2003
Messages
131
When executing an UPDATE query in VBA can I use a variable as a field name? For example:

Dim myStudent as string

myStudent = Forms![frmMasterReportCard]![Student_Name]

mySQL = "UPDATE tblStudentCheck SET ["myStudent"] = '1';"

DoCmd.RunSQL mySQL

I am sure the problem is in the ["myStudent"] portion.

My plan is to send the name of the text box to a module and use this query there. This will save on a lot of coding if I can use the module.

Thanks.
 
mySQL = "UPDATE tblStudentCheck SET [" & myStudent & "] = '1';"

Two things though, '1' is being passed as a string not a number.
If you have fields named after students then you have probably got design problems!

Peter
 
Thanks!

I am using the VBA update query as a flag to indicate if the user has overridden a computed grade. The 1 indicates the user has changed the grade.

Thanks for the help.
 

Users who are viewing this thread

Back
Top Bottom