UPDATE syntax with combobox

cjcobra

Registered User.
Local time
Today, 06:36
Joined
Jan 14, 2011
Messages
25
ok, so it doesn't seem to be working as I thought.

I have a combobox ("SubCat") at the top for Projects, Say I select "Project A". Then I have a combobox ("OpLead") that pulls from a table. I want to update all "Project A"'s with what I select in "OpLead". I have about 10 of these, but working small at first. It's updating the table "All_Info", field "Operational Lead". I tried the following, but then added the "WHERE" that should say "For all records matching "Project A", update to "OpLead".

Code:
strQuerySQL = "UPDATE All_Info SET "
 
'Check if cboComboBox1 is not null, if so add SQL to update that field
If Not IsNull(OpLead) Then
     strQuerySQL = strQuerySQL & "All_Info.Operational Lead = '" & OpLead & "', "
End If
'Copy above for each combobox
 
'Remove the comma & space from the end of the SQL
strQuerySQL = Left(strQuerySQL, Len(strQuerySQL) - 2)
 
'Add ; to the end
strQuerySQL = strQuerySQL & ";"

I thought this would be it.

Code:
strQuerySQL = "UPDATE All_Info " _
        & "SET All_Info.Operational Lead = Forms![Update Form SubProject]![OpLead] " _
        & "WHERE [All_Info]![Project Subcategory] = [Forms]![Update Form SubProject]![SubCat];"

Also, do I need an "Execute" in front of this? I'm attaching this to a button. Thanks!
 
Also, do I need an "Execute" in front of this? I'm attaching this to a button. Thanks!

Currentdb.Execute strQuerySQL cannot refer directly to objects on forms. The values must be read and concatenated into the string.

If the string has references outside of the tables and queries, use:
DoCmd.RunSQL strQuerySQL
 

Users who are viewing this thread

Back
Top Bottom