Handling data from Multiple Option Buttons

dave3944

Board Regular
Joined
Jan 22, 2005
Messages
139
I'm working on a multi-sheet Workbook Print Application for the Shop floor users. As one would expect, there are several printing options presented. I've taken care of the simpler options with few problems. I'm stumped as to how to handle a multi Option Button VBA UserForm.

Here's the scenario:
A UserForm (WbkSheets1) pops up with 4 options. This box is intended to ask the user which Workbook sheet they would like to print. The 4 options represent the 4 Worksheets in the Workbook. The Option buttons are named DWGRev1, Dwg2, Traveler3, and Squawk4.

If the user selects DWGRev1 or Traveler3, they are printed immediately. If the user selects Dwg2 or Squawk4, a Serial Number is required before printing.

To have the user supply the Serial Number they wish to print, I created VBA UserForm OtherSingleSN1 with a TextBox (EnterSNSingle1) and OK and Cancel command buttons. Here's the code for the OtherSingleSN1 box:
Code:
Private Sub SNSingleOK1_Click()
    
    Unload Me
        
    Dim frm As New WbkSheets1
    Dim intBegSN As String
    
 Debug.Print frm.Dwg2.Value
 
    If frm.Dwg2.Value = True Then
        Call PrintDwg
    ElseIf frm.Squawk4.Value = True Then
        Call PrintSquawk
    End If
    
    intBegSN = EnterSNSingle1.Value
 Debug.Print EnterSNSingle1.Value

End Sub
I'm want to retain the value of OptionButton Dwg2 along with User-entered Serial Number and pass them on to the appropriate printing procedure. The variable frm.Dwg2.Value always returns FALSE. The variable intBegSN is a value for the user-supplied Serial Number passed to the printing procedures.

I've tried so many approaches, the code may be totally screwed up and unworkable. The idea is to go from the UserForm WbkSheets1, when Dwg2 or Squawk4 are selected, supply a Serial Number, then print whichever page was selected with the supplied Serial Number. A little sage wisdom would be greatly appreciated
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
instead of a userform, why not have an inputbox?

Code:
findser = inputbox{"What is the Serial Number?")
     if findser = "" then
          exit sub
     end if

'findser is the serial number they input!
'Use the input the way you want without a form!
 
Upvote 0
It works, but I wish there was a way to use the TextBox, for the sake of continuity and elegance.

But this way gets the job done. Thanks for the tip. Sometimes we want to overcomplicate things.
 
Upvote 0
code:
--------------------------------------------------------------------------------
Private Sub SNSingleOK1_Click()

Unload Me

Dim frm As New WbkSheets1
Dim intBegSN As String

Debug.Print frm.Dwg2.Value

If frm.Dwg2.Value = True Then
Call PrintDwg
ElseIf frm.Squawk4.Value = True Then
Call PrintSquawk
End If

intBegSN = EnterSNSingle1.Value
Debug.Print EnterSNSingle1.Value

End Sub
I tried a couple of more things. One of them was to change the highlighted text to Hide.Me. I figured this might retain the variable instead of dumping it on the Unload Me command. I was right. The final working code is:
Code:
Private Sub Dwg2_Click()
    
    Dim SerNum As String
    
    SN1.Show
    
    SerNum = SN1.EnterSNInput1.Value

    If SerNum = "" Then
        Exit Sub
    End If

'Fill cell L6 with the initial serial number
    Sheets("Dwg").Range("ser_no") = SerNum

'Print all four sheets for the first serial number seat
    Sheets("Dwg").Select
    Sheets("Dwg").Activate
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    Range("ser_no").Select

    ActiveWorkbook.Save
    
    Unload SN1
    
End Sub
This code is placed in UserForm (WbkSheets1). The only code in the Serial Number Text Box is Me.Hide. I Unload the Serial Number Text Box after the WkbSheets form is finished.

Thanks, again for your help.
 
Upvote 0

Forum statistics

Threads
1,203,563
Messages
6,056,092
Members
444,846
Latest member
pbailey

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top