option button to print reports

ksgirl

Registered User.
Local time
Today, 15:36
Joined
Jul 1, 2002
Messages
53
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?
 
Give me enough time and I'll figure it out....something simple of course, but I thought I would post an answer! I forgot to change 'Dim stDocName As String' to 'Dim stDocName1, stDocName2, stDocName3 As String'
I knew it was something simple!
 
You beatb me with your solved post but:

Something like this may be more efficient

Select Case Me.optgrpNav.Value
Case 1
DoCmd.OpenForm ("frmReports")
Case 2
DoCmd.OpenForm ("frmSearch")
Case 3
DoCmd.OpenForm ("frmCust")
DoCmd.GoToRecord , ("frmCust"), acNewRec
Case 4
DoCmd.OpenForm ("frmDealer")
DoCmd.GoToRecord , ("frmDealer"), acNewRec
Case 5
DoCmd.OpenForm ("frmParts")
DoCmd.GoToRecord , ("frmParts"), acNewRec
Case 6
DoCmd.OpenForm ("frmModel")
DoCmd.GoToRecord , ("frmModel"), acNewRec
End Select
 
Declaring variables

KSgirl:

Just an FYI, but you may already know this. Take care in the way you have declared your variables here (you may have just short-cutted in pseudo-code, if that is the case I aplogise)

Dim stDocName1, stDocName2, stDocName3 As String

As it stands here, only stDocName3 is explicitly declared as a String, the other two are actually variants. Each variable needs to be declared specifically if you want to do them on one line:

Dim stDocName1 As String, stDocName2 As String, stDocName3 As String


DT
 

Users who are viewing this thread

Back
Top Bottom