Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2003
    Location
    UK
    Posts
    85

    Question Unanswered: How to link option group with various comd buttons

    Dear All

    I have got a little query about option group and VB codes. I explain my problem here

    I have got set up an option group with 4 options and 7 command buttons each opens a different report based on the selected option.

    Now the problem is do I have to write separate VB codes on each command button's OnClick event to open different reports depending on one option selected in option group?

    What I want is,

    If option1 is selected and CmdReport1 is clicked, it would preview or print Report1 and if CmdReport2 is clicked, it would preview or print Report2 and so on.

    The only problem with the present situation is that there would be huge list of codes in VB window and it would become complicated to handle.

    I hope I have explained my problem.

    Looking forward to your reply.

    Thanks

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Cool

    I think you can do it with only one Button, under the click event make a SELECT statement which checks the RadioButtons or the CheckBoxes

    Somthing like that:

    Select Case urFrame_Name
    CASE 1 ' Open Report 1
    DoCmd.OpenReport "Rep1"

    CASE 2 ' Open Report 2
    DoCmd.OpenReport "Rep1"

    CASE 3
    msgbox("Please check your Options")
    CASE ELSE

    End Select

    Good Luck

  3. #3
    Join Date
    Mar 2003
    Location
    UK
    Posts
    85
    I think I have not been able to convey my problem properly. I try again.

    I have 4 options in an option group

    Option1
    Option2
    Option3
    Option4

    I have got say for now 5 different reports to print / preview

    Report1
    Report2
    Report3
    Report4
    Report5

    When I click on option 1, it filters the data based on selection in option1 and then I click on Report1 command button Report 1 opens

    Option 1 remains selected and I click on command button for Report 2 Report 2 opens

    Option 1 remains selected and I click on command button for Report 3 Report 3 opens
    Option 1 remains selected and I click on command button for Report 4 Report 4 opens
    and so on.

    I hope it is a bit clear now.

  4. #4
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile

    Originally posted by dbase
    I think I have not been able to convey my problem properly. I try again.

    I have 4 options in an option group

    Option1
    Option2
    Option3
    Option4

    I have got say for now 5 different reports to print / preview

    Report1
    Report2
    Report3
    Report4
    Report5

    When I click on option 1, it filters the data based on selection in option1 and then I click on Report1 command button Report 1 opens

    Option 1 remains selected and I click on command button for Report 2 Report 2 opens

    Option 1 remains selected and I click on command button for Report 3 Report 3 opens
    Option 1 remains selected and I click on command button for Report 4 Report 4 opens
    and so on.

    I hope it is a bit clear now.
    Write a function or procedure that accepts two values, the value of the option selected and the report name. Each time a different button is pressed, it runs the procedure and passes to it the name of the report and the currently selected option. Ex. Private Sub GetReport(name as string, option as integer)

    When you click a command button: Use whatever means you want to determine which option button is selected and call the Sub. GetReport "rptWhatever", number of option).

    Just an example of what you could do. There are lots of other ways.

    Hope this helps.

    Gregg

  5. #5
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    Further to what Gregg wrote:

    Each button will have to have an on click event.
    To have to maintain only one version of the option button code, you can put a call to another subroutine in each of the on click event.

    Private Sub Report1_OnClick()
    call PrintIt("Report1Name")
    End Sub

    Private Sub Report1_OnClick()
    call PrintIt("Report1Name")
    End Sub
    .
    .
    .

    Private Sub PrintIt(rptName as string)
    Dim stWhere as String
    Select Case Me!OptionGroup
    Case 1
    stwhere = "[rptDate] <= #2003/01/01#"
    Case 2
    stwhere = "[rptDate] > #2003/01/01#"
    .
    .
    .
    Case Else 'Unfiltered
    stwhere = ""
    End Select
    DoCmd.OpenReport rptName, acViewPreview, , stwhere
    end sub

  6. #6
    Join Date
    Mar 2003
    Location
    UK
    Posts
    85

    Thumbs up

    Thank you very much for your suggestions.

    I have tried it and it worked exactly the way I wanted.

    Thanks again for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •