Link to home
Create AccountLog in
Avatar of Kevin
KevinFlag for United States of America

asked on

BeforeUpdate Subroutine on Checkbox

I posted a question last week asking “How to remove/Delete data when unchecking a Checkbox”. This question was answered, but in working the problem I came up with a different issue. I have explained what is happening below and ask for assistance figuring this out.
The objective:
If the Return checkbox is checked, and the date and time are entered this is a complete record.
If the “Returned” checkbox is checked, and for some reason it is decided to uncheck it, which would (hide) the “Return Date” or Return Time” controls this data needs to be removed. This keep the database from having data in the table that can’t be seen on the form.
Currently the code in the Before Update Subroutine is working backwards.
On Record one (1) the checkbox is checked and both “Return Date” and “Return Time” are empty. When unchecked the message box should not fire, but it does.
On Record two (2) the checkbox is checked and both “Return Date” and “Return Time” are entered. When unchecked the message box does not fire, and both controls are made invisible leaving the data in the fields. It should give a warning from the message box.
These two conditions are working backwards of what should happen. I have studied the chkReturned_BeforeUpdate code, but just don’t see where the problem is.
Avatar of irudyk
Flag of Canada image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Kevin


I hope this is not asking to much. Can you explain the difference.
Me.txtReturnDate.Value, "") <> "" Then

"" = Null
<> = Not equal
txtReturnDate.Value, is null, and not equal to ?. I am not sure how to read the section after )
Avatar of Kevin


That worked great, Thank you for your help!
Trying to learn something new with each problem.
The Nz function has 2 arguments, the 2nd of which indicates what to return if the the value in the 1st argument is null. Since you didn't have this argument set, you were not getting a "" result returned if the value was null. I used <> "" afterwards because if the value of the field was not equal to "" then it has some value entered which you wanted to be cleared (set to "").
Avatar of Kevin


I understand.
Thank you for the solution and the explanation.