Checkbox for reports wont accept the selcted boxes


B

BZeyger

Hello,

I have a simple VBA form which has 4 checkboxes.
chk1
chk2
chk3
chk4

The form laod event has chk3 defaulted as checked.

The user is supposed to check off the boxes for which report they want to run.
If I uncheck chk3 or select any other check box, the report does not show up.

Is there an Update command I should use in the click event of the run button?
 
Ad

Advertisements

D

Dirk Goldgar

BZeyger said:
Hello,

I have a simple VBA form which has 4 checkboxes.
chk1
chk2
chk3
chk4

The form laod event has chk3 defaulted as checked.

The user is supposed to check off the boxes for which report they want to
run.
If I uncheck chk3 or select any other check box, the report does not show
up.

Is there an Update command I should use in the click event of the run
button?


We'd need to know more about how these check boxes control the reporting.
Are they referred to by the report's recordsource? Is there code in the
Click event of the "run button" you mention that refers to these check
boxes? If so, please post the code. Are the check boxes unbound, or are
they bound to fields in a table somewhere?
 
B

BZeyger

The checkboxes only pull up a report...there are no record sources.
The code in the run buttons click event is

If chk1.Value = 1 Then
DoCmd.OpenReport "Report 1", acViewPreview
End If

If chk2.Value = 1 Then
DoCmd.OpenReport "Report 2", acViewPreview
End If

If chk3.Value = 1 Then
DoCmd.OpenReport "Report 3", acViewPreview
End If

If chk4.Value = 1 Then
DoCmd.OpenReport "Report 4", acViewPreview
End If


These are not nested right now, but they will be when the code is complete.
 
Ad

Advertisements

D

Dirk Goldgar

BZeyger said:
The checkboxes only pull up a report...there are no record sources.
The code in the run buttons click event is

If chk1.Value = 1 Then
DoCmd.OpenReport "Report 1", acViewPreview
End If

If chk2.Value = 1 Then
DoCmd.OpenReport "Report 2", acViewPreview
End If

If chk3.Value = 1 Then
DoCmd.OpenReport "Report 3", acViewPreview
End If

If chk4.Value = 1 Then
DoCmd.OpenReport "Report 4", acViewPreview
End If


Unbound check boxes can have values of -1 (True), 0 (False), or Null.
Change your code like this:

'----- start of suggested code -----
If (chk1.Value) Then
DoCmd.OpenReport "Report 1", acViewPreview
End If

If (chk2.Value) Then
DoCmd.OpenReport "Report 2", acViewPreview
End If

If (chk3.Value) Then
DoCmd.OpenReport "Report 3", acViewPreview
End If

If (chk4.Value) Then
DoCmd.OpenReport "Report 4", acViewPreview
End If

'----- end of suggested code -----

That syntax -- "If (chk1.Value) Then" -- eliminates any possibility of
confusion over whether the checked box is -1 or 1.
 

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