VBA script for option group

Prayder

Registered User.
Local time
Today, 11:16
Joined
Mar 20, 2013
Messages
303
I have created an option group with 4 buttons and I also created a command button labeled (GO) and what I am wanting is the (GO) button to reference back to which ever of the 4 buttons selected and open the report based off that button. But I am needing help with the vba for the (GO) button. Any help would be greatly appreciated....
 
The key with an option group is that you test the value of the frame, not the options. With 4 options I'd probably use Select/Case.
 
Ok.... but what vb am I using to open a the reports? Each button references a report so basically when I select (stock Requisitions buton) and then click on the (GO) button I want it to open the "Stock Req Project" report
 
What Paul meant was the Option group button is only for display, in the design view if you select the option it will see the appropriate value, normally they are numbers, so your VB code will be something like..
Code:
Private Sub goButtonName_Click()
    Dim rptName As String
    Select Case Me.yourOptionGroupFrameName
        Case 1
            rptName = "TheReportForOption 1"
        Case 2
            rptName = "TheReportForOption 2"
        Case 3
            rptName = "TheReportForOption 3"
        Case 4
            rptName = "TheReportForOption 4"
        Case Else
            MsgBox "Not a valid Option", vbInformation
            Exit Sub
    End Select
    DoCmd.openReport rptName
End Sub
 
Code:
Private Sub gobutton_Click()
Select Case Me.Label1.value
Case 1
DoCmd.openreport ("Stock Req Project")
 
Case 2
DoCmd.openreport ("General Req Project")
 
Case 3
DoCmd.openreport ("Composite Project")
 
Case 4
DoCmd.openreport ("Lumber Sorter Project")
End Select
End Sub]

This is what I currently have for the event procedure for the (GO) button but it comes back saying method or data member not found and highlights the value in the ME statement.
 
That must not be the name of the frame. It appears to be a label.
 
That must not be the name of the frame. It appears to be a label.
Paul am a bit :confused: I thought the OP had a Option Group, which means it can have only one option, if using the "toggle button", whihc is what I thought the OP was using, would the code still not use the OptionFrame to select the value?? Or have I got something fundamentally wrong here?
 
I guess I'm confused, because I said to test the value of the frame. OP is getting an error that appears to be caused by trying to test the value of a label rather than the frame.
 
Here is my current coding for the (GO) button once the selection is made:

Code:
  Private Sub gobutton_Click()
    Select Case Me.Frame0.value
        Case 1
            DoCmd.openreport ("Stock Req Project")
        Case 2
            DoCmd.openreport ("General Req Project")
        Case 3
            DoCmd.openreport ("Composite Project")
        Case 4
            DoCmd.openreport ("Lumber Sorter Project")
        Case Else
            MsgBox "Not a valid Option", vbInformation
    End Select
   
End Sub

When I click the (GO) button all it does is print... the report doesn't actually display on the screen
 
Look in help at the arguments for OpenReport. One of them controls that.
 
Try adding the acPreview as the view..
Code:
DoCmd.OpenReport "reportName", acViewPreview
 

Users who are viewing this thread

Back
Top Bottom