Need to get VBA code to tell which checkboxes are selected on form

B

Brent E

Good afternoon,

I am using a VBA module to open an Access form and offer several check boxes
to offer a user to select which documents they would like to print, but I
need to know what VBA commands to use that will tell if a check box is
checked or not. I tried using an If statement like: (Note check29 is name of
checkbox on form)

If check29 = True Then
Debug.Print "Print 29"
Else
End If

And procedure will compile and run, but won't print anything in the
immediate window. I tried to also use a boolean variable and set variable =
check29 and used that in If statement but still no difference. Should I use a
Me.check29 statement instead? If so, I am not sure how to do this.

Any suggestions? Thanks.

Cordially,
 
B

Brent E

I forgot to ask. I also need to now how to reference the form in my VBA
module. I defined a variable "CurrForm as Form" to use to reference my
form but I am notsure how to do that, and how to refernce any text boxes,
etc. on that form. If I can figure that out, I think I will know how
to check if the boxes are checked.
 
T

Tim Ferguson

I need to know what VBA commands to use that will tell if a
check box is checked or not. I tried using an If statement like: (Note
check29 is name of checkbox on form)

If check29 = True Then
Debug.Print "Print 29"
End If

And procedure will compile and run, but won't print anything in the
immediate window.

Hmm: where is this code running and how are you calling it and how are
you opening the form?

If the code is in the form's own module, then this should work fine. I
would prefix it with the Me object

If Me!Check29

but it works quite happily without. In VBA, comparing anything with TRUE
is true if it's non-zero; only zero = FALSE. Any control value, though,
can be NULL, so you need to make sure that your control is not grey.

If you are running the code in a module, then you'll need to reference
the control properly:

If forms("MyForm").Controls("check29) = True Then...

Finally, check that the code is being called at all:

If check29 = True then
debug.print "29 is true"

Elseif check29 = False
debug.print "29 is false"

Else
debug.print "29 is neither true nor false"

End if

because if the control is null, it'll fail =True and =False.


I forgot to ask. I also need to now how to reference the form in my
VBA module. I defined a variable "CurrForm as Form" to use to
reference my form but I am notsure how to do that, and how to refernce
any text boxes, etc. on that form. If I can figure that out, I
think I will know how to check if the boxes are checked.

See above. You can use a variable if you want:

dim frm as Form

set frm = Forms("MyForm")

If frm!check29 Then ...


The Me object is a shorthand for the form that contains the module that
contains the code that the Me appears in... IYSWIM

Hope it helps


Tim F
 

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