Set All Bollean Datatype to False on reset

  • Thread starter edisonl via AccessMonster.com
  • Start date
E

edisonl via AccessMonster.com

Hi,

any idea how can I explicitly set all Boolean Datatype within a form to FALSE
with a On_Click Button ?

Regards, Edison
 
A

Arvin Meyer [MVP]

edisonl via AccessMonster.com said:
Hi,

any idea how can I explicitly set all Boolean Datatype within a form to
FALSE
with a On_Click Button ?

Put this in a standard module named basUtilities or something:

Public Sub CheckIt(frm As Form)

Dim ctl As Control

For Each ctl In frm.Controls
If ctl.Controltype = acCheckBox
ctl.Value = False
End If

Next ctl

Set ctl = Nothing
Set frm = Nothing

End Sub

Then call it from a command button:

Private Sub cmdWhatever_Click()
Call CheckIt(Me)
End Sub
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Disclaimer: Any code or opinions are offered here as is. Some of that
code has been well tested for number of years. Some of it is untested
"aircode" typed directly into the post. Some may be code from other
authors. Some of the products recommended have been purchased and
used by the author. Others have been furnished by their manufacturers.
Still others have not been personally tested, but have been
recommended by others whom this author respects.
 
T

Tom van Stiphout

On Fri, 09 Oct 2009 03:42:41 GMT, "edisonl via AccessMonster.com"

Easier to do all checkboxes:
dim ctl as control
for each ctl in me.controls
if typeof(ctl) is checkbox then
ctl.value = false
endif
next

-Tom.
Microsoft Access MVP
 
E

edisonl via AccessMonster.com

Hi Tom,

Sorry I may have not explain myself clearly.

What I wanted to achieve was to set Boolean that is declared as public
variable within a form in VB editor as False on exit or Form_Load

Regards, Edison
 
T

Tom van Stiphout

On Fri, 09 Oct 2009 08:55:26 GMT, "edisonl via AccessMonster.com"

Ah, got you. There is no way to set multiple variables to True or
False with one statement. So you'll have to write a statement for
each. I would put it all in a subroutine:
private sub SetAllBooleans(byval blnValue as boolean)
myFirstBool = blnValue
mySecondBool = blnValue
'etc
end sub

Then call this with:
SetAllBooleans True
or
SetAllBooleans False

This way at least you don't have to write each statement twice, once
for true and once for false.

-Tom.
Microsoft Access MVP
 
A

Arvin Meyer [MVP]

If it's a single Public Boolean variable, you can more reliably set it in
form Current, unless you want it to persist for the session. In either case,
you simply set it to false, no matter where you set it:

blnVariableName = False

and if there are several of them just do a loop as either Tom or I have
demonstrated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top