SQL Update issue

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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]
 
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] & "'"
 
Back
Top