Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Option buttons to print reports

Status
Not open for further replies.

ksgirl

Programmer
Jul 9, 2002
12
US
I have two forms. The first one displays a record and the second one is a 'print page'. On this second form I have five option buttons and another command button at the bottom. I want the user to select which option they want, and click on the command button 'Print', to print whatever selection they've choosen. (I don't need to have the report previewed, I just need it to print!) Here are the option buttons:
1- Print Clearance Sheet
2- Print Tag Sheet
3- Print Tags
4- Print all the above
5- Print Clearance and Tag Sheet

I have played around with this, and came up with the following code to be placed in the OnClick of the command button:

Private Sub print_button_Click()
On Error GoTo Err_print_button_Click

Dim stDocName As String

stDocName1 = "Clearance Report"
stDocName2 = "Tag (Summary) Print off"
stDocName3 = "Clearance Tag Print"

If OptionButton.Value = 1 Then
DoCmd.OpenReport stDocName1, acNormal

ElseIf OptionButton.Value = 2 Then
DoCmd.OpenReport stDocName2, acNormal

ElseIf OptionButton.Value = 3 Then
DoCmd.OpenReport stDocName3, acNormal

ElseIf OptionButton.Value = 4 Then
DoCmd.OpenReport stDocName1, acNormal
DoCmd.OpenReport stDocName2, acNormal
DoCmd.OpenReport stDocName3, acNormal

ElseIf OptionButton.Value = 5 Then
DoCmd.OpenReport stDocName1, acNormal
DoCmd.OpenReport stDocName2, acNormal
End If

Exit_print_button_Click:
Exit Sub

Err_print_button_Click:
MsgBox Err.Description
Resume Exit_print_button_Click

End Sub

The only problem with this, is that when I click on the button it gives me a "object required" notification.... and for the life of me I can't figure out what is wrong. Does anyone have any suggestions?
 
I noticed that you didn't define your variables correctly, this won't work:
Dim stDocName As String
for stDocName1 2 & 3, they must be declared seperatly, like:

Dim stDocName1, stDocName2, stDocName3 As String

if that doesn't fix it, then take out the line 'On Error...' and run it. Hit debug when it crashes and tell us where it is crashing at.

HTH!

-Brad
 
AHH...Ok I made the changes you suggested and now I get a "Run Time Error '424'...Object required" error. I debuged, and it is crashing on the 'If OptionButton.Value = 1 Then' line. Any suggestions now?
 
What is OptionButton? a radio button? make sure that it's name is OptionButton, under it's properties list.

-Brad
 
Hey thanks for your help. I had deleted my original 'frame' for the option group and add a new one while designing the form.....subsequently I forgot to change the name of the 'frame name'..... If that makes any sense! It now works like a charm. Thanks again!
 
You might consider using a Case structure instead of the If Else If structure. Both ways work, and this is just a suggestion.

Select Case OptionButton.Value
Case 1
DoCmd.OpenReport stDocName1, acNormal

Case 2
DoCmd.OpenReport stDocName2, acNormal

Case 3
DoCmd.OpenReport stDocName3, acNormal

Case 4
DoCmd.OpenReport stDocName1, acNormal
DoCmd.OpenReport stDocName2, acNormal
DoCmd.OpenReport stDocName3, acNormal

Case 5
DoCmd.OpenReport stDocName1, acNormal
DoCmd.OpenReport stDocName2, acNormal
End Select


Best, dz
dzaccess@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top