SQL Update issue

G

Guest

Hello

I have made a query in VBA code to update the records of a table triggered
by the After Update event of a combobox. The query is designed to update any
record that has a field value equal to the string value of the combobox and
set the field “Shared†checkbox to True.
The code is:
DoCmd.RunSQL "UPDATE [tblItems] SET [Shared] = True WHERE [ItemCode] =
Forms![frmItems]![frmItemsSubform]![cboItemCode]; "

But no any record meeting the criterion is updated; do you see where the
problem is?

Thanks

GL
 
G

Guest

Change this
Forms![frmItems]![frmItemsSubform]![cboItemCode]

To
Forms![frmItems]![frmItemsSubform].Form![cboItemCode]

You are missing the Form in the path

Forms![MainFormName]![SubFormName].Form![FieldName]
 
G

Guest

Another option you can use

DoCmd.RunSQL "UPDATE [tblItems] SET [Shared] = True WHERE [ItemCode] = " &
Forms![frmItems]![frmItemsSubform].Form![cboItemCode]

Or, if the code is text type, then
DoCmd.RunSQL "UPDATE [tblItems] SET [Shared] = True WHERE [ItemCode] = '" &
Forms![frmItems]![frmItemsSubform].Form![cboItemCode] & "'"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top