Avatar of Kevin
Kevin
Flag 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.
RefusedBooking_postversion_Answer1.zip
DatabasesVBA

Avatar of undefined
Last Comment
Kevin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
irudyk

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Kevin

ASKER
irudyk,
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 )
Kevin

ASKER
That worked great, Thank you for your help!
Trying to learn something new with each problem.
irudyk

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 "").
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Kevin

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