dailymeat
asked on
Updating Yes/No Field
Have a table named "DownloadFromScanner", need based on some filters (s or r) and (VendorID) to set Yes/No field either to Yes or No.
I made a form "ScannerUpdate) and subform "ScannerUpdateSubform" this subform is based in a query name ScannerUpdate Query".
In the form I have 2 buttons one is named "Yes"and the code is CurrentProject.Connection. Execute "UPDATE [ScannerUpdateQuery] SET [RecordRead]=True".
The other button is named "No" and the code is CurrentProject.Connection. Execute "UPDATE [ScannerUpdateQuery] SET [RecordRead ]=False".
Once I open the Form and subform and applied the filters with the records I want to update I either press yes or no buttons.
Problem is that all the records in the query are updated regardless whether they are in the filter selection or not.
I made a form "ScannerUpdate) and subform "ScannerUpdateSubform" this subform is based in a query name ScannerUpdate Query".
In the form I have 2 buttons one is named "Yes"and the code is CurrentProject.Connection.
The other button is named "No" and the code is CurrentProject.Connection.
Once I open the Form and subform and applied the filters with the records I want to update I either press yes or no buttons.
Problem is that all the records in the query are updated regardless whether they are in the filter selection or not.
you have to revise your SQL statement to include a WHERE condition
"UPDATE [ScannerUpdateQuery] SET [RecordRead ]=False WHERE <criteria here>"
"UPDATE [ScannerUpdateQuery] SET [RecordRead ]=False WHERE <criteria here>"
The query doesn't use the form filter. You need to include criteria in the update query. You can build the SQL on the fly with VBA or you can use querydefs with variable arguments (which is my method).
You will need to add the filter fields to the form's header either as text boxes or combos. The update query will reference those filter fields.
The querydef:
UPDATE [ScannerUpdateQuery] SET [RecordRead]= Forms!yourform!ReadOption
Where fldA = Forms!yourform!searchfldA AND fldB = Forms!yourform!searchfldB;
You will need to add the filter fields to the form's header either as text boxes or combos. The update query will reference those filter fields.
The querydef:
UPDATE [ScannerUpdateQuery] SET [RecordRead]= Forms!yourform!ReadOption
Where fldA = Forms!yourform!searchfldA AND fldB = Forms!yourform!searchfldB;
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great work!!
Thanks
Thanks
Try this:
in the Yes or No button click events:
Open in new window
That should pull whatever filter you have established on the subform into your update query. You will need to change "subformControlName" in the code above to the actual name of the subform control (not the source object).