Set all controls to Null on exit of form if fomed completed checkbox iis not selected (1 Viewer)

Db-why-not

Registered User.
Local time
Today, 06:38
Joined
Sep 17, 2019
Messages
155
Hello,
Is there a easy way to set all the controls of a form to Null values on exit/ on close of form if form_completed checkbox is not checked. Can you do it without referencing every single control on a form? I always seem to mess up the syntax for form references with controls when I have the code run on subforms.

Does anyone know of a good tutorial on syntax for referring to controls from subforms and main forms? Thanks.

What I'm trying to do is I have a data entry form with option group buttons and a text box. I want user to select form completed checkbox when they have completed the form. When they click on form completed checkbox vba will check all controls for null values, if any null values found it will leave form_completed unchecked. If the user exits the form before checking the form completed box then it will reset all values on the form to null. If form completed is checked then the form will save and leave values as is and exit.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:38
Joined
Oct 29, 2018
Messages
13,692
Hi. Are we talking a bound or unbound form? To check each control, you can use the Tag property and then loop through all the controls using For Each construct.
 

Db-why-not

Registered User.
Local time
Today, 06:38
Joined
Sep 17, 2019
Messages
155
Hi. Are we talking a bound or unbound form? To check each control, you can use the Tag property and then loop through all the controls using For Each construct.
A bound form.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:38
Joined
Feb 28, 2001
Messages
18,701
There is no easy "one command does it all" but there is no reason you couldn't write a simple "FOR EACH control-variable IN ME.CONTROLS..." type of loop.


It will be touching every control, so you need to determine what control you are looking at. Not all controls can even HAVE a value. Here is a list of control types.


The skeleton of this might be:

Code:
FOR EACH ctlvar IN ME.CONTROLS
    SELECT CASE ctlvar.CONTROLTYPE
        CASE AcTextBox
            ctlvar = ""
        CASE AcCheckBox
            ctlvar = FALSE
        CASE AcOptionGroup
            ctlvar = <whatever is the lowest allowed value>
        CASE etc. etc.
        CASE ELSE
' do nothing because anything not in list has no value to reset
    END SELECT
NEXT ctlvar
 

arnelgp

error reading drive A:
Local time
Today, 20:38
Joined
May 7, 2009
Messages
11,121
sample of what you requested on post#1, a Data Entry form.
 

Attachments

  • validateByCheckbox.zip
    47.2 KB · Views: 25

Users who are viewing this thread

Top Bottom