I'm writing an application in Access 2003 that prints customer-specific pricelists. I have a simple form that asks the user to enter the customer ID and select the product category or categories for the items to print pricing for.
The form has the following controls:
txt_Customer - an unbound text box
chk_all - a checkbox
chk_grp1 - a checkbox
chk_grp2 - a checkbox
chk_grp3 - a checkbox
The checkboxes are not in an option group because the user must be allowed to select any combination of grps 1, 2, or 3.
In the On LostFocus property of txt_Customer, I've got a DLookup function that looks up the entered customer ID in a table and displays an error message in a MsgBox if the customer ID is not found. After the user clicks OK to close the MsgBox, I want to clear the entire form, including any checkboxes that may have been checked.
I've defined a public function that runs this code which works great if I attach it to it's own button on the form and run it separately.
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then
ctl.Value = False
End If
Next
However, when I call it from inside the function that runs on LostFocus, it doesn't work.
Private Sub txt_Customer_LostFocus()
If IsNull(DLookup("[Name]", "dbo_ARCUSTOMER", "[Customer]='" & [Forms]![GetCustomer]![txt
_Customer]
& "'")) Then
MsgBox ("Customer not found. Please enter a valid customer ID code.")
Me!txt_Customer = ""
UncheckAll 'a public function that runs the code above to uncheck all checkboxes
End If
End Sub
The user enters an invalid customer ID and selects a checkbox, the above code runs and displays the message to the user, the user clicks OK to close the MsgBox, the txt_Customer field is cleared (ready for new input) AND the checkbox remains checked.
Please advise how I can clear the checkboxes after a MsgBox message has been displayed.
Many thanks!
Start Free Trial