Update Statement with Where Combobox (1 Viewer)

fitzgeraldrl25

New member
Local time
Today, 05:14
Joined
Sep 13, 2019
Messages
3
What I am trying to accomplish is update multiple records in a table that meets criteria that is stored in a combobox. The field that I am trying to update set to Null (also a combobox stored as text, key field hiding).

I have been able to get the where statement working with a checkbox


Code that I have tried (code works without WHERE statement
Code:
CurrentDb.Execute "UPDATE [Main] SET [TAD]= Null" & "WHERE [TAD] = Me.TADSlctRtrn.Value"

CurrentDb.Execute "UPDATE [Main] SET [TAD]= Null" & "WHERE [TAD] = Me.TADSlctRtrn.text"
 
CurrentDb.Execute "UPDATE Main SET TAD = Null" & "WHERE TAD = Me.TADSlctRtrn.Value"
 

June7

AWF VIP
Local time
Today, 01:14
Joined
Mar 9, 2014
Messages
5,425
Concatenation is wrong. Can't use Me. if you embed the control reference between quote marks - concatenate the control reference.

CurrentDb.Execute "UPDATE [Main] SET [TAD] = Null WHERE [TAD] = " & Me.TADSlctRtrn

What kind of field is TAD?
 

fitzgeraldrl25

New member
Local time
Today, 05:14
Joined
Sep 13, 2019
Messages
3
Thank you for the help.

I tried the code that you provided and received runtime error 3075:

syntax error (missing operator) in query expression '[TAD] = jackson'

[Main].[TAD] is a combobox stored as text, key field hiding.
[TADSlctRtrn] is a unbound combobox stored as text, key field hiding on a unbound form
both fields are linked to the same data.
 

June7

AWF VIP
Local time
Today, 01:14
Joined
Mar 9, 2014
Messages
5,425
So TAD is a text type field. Passing a string criteria requires apostrophe delimiters.

CurrentDb.Execute "UPDATE [Main] SET [TAD] = Null WHERE [TAD] = '" & Me.TADSlctRtrn & "'"

Date/type field requires # delimiter.
 

fitzgeraldrl25

New member
Local time
Today, 05:14
Joined
Sep 13, 2019
Messages
3
Thank you so much that worked.

Solved

Code that worked
CurrentDb.Execute "UPDATE [Main] SET [TAD] = Null WHERE [TAD] = '" & Me.TADSlctRtrn & "'"
 

Users who are viewing this thread

Top Bottom