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

Db-why-not

Registered User.
Local time
Today, 12:06
Joined
Sep 17, 2019
Messages
160
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.
 
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.
 
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.
 
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
 

Users who are viewing this thread

Back
Top Bottom