Link to home
Start Free TrialLog in
Avatar of damixa
damixaFlag for Denmark

asked on

How to update a checkbox on exit

I have a form that I have attached here that we will call Form1. On this form I can check the assigned checkbox or uncheck it. I also have a second form that is open that I call Form2

I need to add an action that does the following

onExit
if Forms!Form2!txtField1 is null

unselect all the "Assigned" checkboxes on Form1

Else
Just leave the checkboxes I have selected checked as they are

I'm a bit rusty on VBA. Much appreciated
This is Form1
User generated image
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

try using the Unload event of form2


private sub form_Unload(cancel as Integer)
on error resume next
If IsNull(Me.txtField1) then
     with forms!form1.Recordset
          do until .EOF
          .edit
          !Assigned = 0
          .update
          .moveNext
          loop
     end with
end If
end sub
Avatar of damixa

ASKER

Hi Capricorn,
Thanks for your help.

one tiny problem.

lets say I have checked
record1
record2
record 3

when I try to close the form, if I have selected record2 for example it will uncheck everything starting at record2, so the record 1 will still be selected and assiged.

is there a way I can add some code to start at the begining of the form and not at the record I have selected?

thanks again, this has beeen very helpful
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of damixa

ASKER

thanks,
as always amazing work