Need VBA assistance for check boxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good afternoon,

I am using a VBA module to open an Access form. Form contains several check
boxes (made is design view, not created by code) 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 set a command button called "Print Selection" to run code
that I want to print out any documents selected. (See code below) And
procedure will compile and run, and the form opens but if I check box 29,
nothing prints in the immediate window no matter if box is checked or not. I
am curoius if I have to refresh my form or anything after that opens and I
check a box?

I think What I need to know is how to reference the checkboxes on the form,
and if they should automatically sense a change in state, or do I need to do
something for them to sense a change in state on the form? (Note check29 is
name of checkbox on form) This is my code:

DoCmd.OpenForm "Graphs Print Selection", acNormal, "", "", , acNormal
If Check29 = True Then
Debug.Print "29"
Else
END If

Do I need to use a Me.Check29 or a get command to refresh box, or how does
this know that a box is checked? What am I doing wrong? Thanks.

Cordially,
 
Yes, you should use Me.Check29.

I'm not quite sure what you have in mind by "automatically sense a change in
state". In general, you put code in the checkbox's AfterUpdate event if you
want something to happen when the status of the checkbox changes.
 
Hi,
You don't need to refresh your form or anything.
Your if statement should work if your box is checked.

Just to be clear, the code below is running within the form that
has your checkbox, right? You're not trying to interrogate a checkbox
that's on the form your code opens, right?

Try setting a breakpoint to see what happens as you step through the code.
 
Brent said:
I am using a VBA module to open an Access form. Form contains several check
boxes (made is design view, not created by code) 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 set a command button called "Print Selection" to run code
that I want to print out any documents selected. (See code below) And
procedure will compile and run, and the form opens but if I check box 29,
nothing prints in the immediate window no matter if box is checked or not. I
am curoius if I have to refresh my form or anything after that opens and I
check a box?

I think What I need to know is how to reference the checkboxes on the form,
and if they should automatically sense a change in state, or do I need to do
something for them to sense a change in state on the form? (Note check29 is
name of checkbox on form) This is my code:

DoCmd.OpenForm "Graphs Print Selection", acNormal, "", "", , acNormal
If Check29 = True Then
Debug.Print "29"
Else
END If

Do I need to use a Me.Check29 or a get command to refresh box, or how does
this know that a box is checked? What am I doing wrong? Thanks.


You are suffering from a major misperception. Primarily
that your code module procedure is synchronous with the
form. Once you execute the OpenForm method, your code loses
control of the form.

All the code associated with actions on the form need to be
in the form's event procedures. In this case, you don't
care when if a user sets or clears a check box. (If you did
care, each check box's AfterUpdate event will notify you
about the value changing). You can perform whatever
activities you need for each check box (as your code does
now) in the command button's Click event procedure.
 
Back
Top