Results 1 to 10 of 10
  1. #1
    tomazm71 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    10

    Option buttons and buttons

    Hi guys,



    Is there anyone who could help with this one.

    I've created a form with Option buttons and buttons. I would like to have one option button checked and click the button with the country, so the report will appear showing all personnel from a Specific country and having the specialising in Spec1. When I choose another spec and change the country another report will pop up. All queries and reports are ready.

    How do I set it up? I have tried something like this, but it's not working. This is for the US button and when Spec1 is checked.

    Private Sub Command127_Click()

    If OptSpec1.Value = True Then
    DoCmd.OpenReport "RptUK_Spec1", acViewReport
    Else
    DoCmd.OpenReport "RptUK", acViewReport
    End If

    End Sub

    Thanks a lot,
    Tom
    Attached Thumbnails Attached Thumbnails ex1.jpg  

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    you should have 2 option groups, 1 for spec, 1 for country, and 1 button to open all:

    the FRAME holds the value of the OgrSpec
    use this value to filter
    DoCmd.OpenReport "Rpt" & fraCountry, acViewReport,,"[specFld]='" & fraOgrSpec & "'"

    or your version:
    DoCmd.OpenReport ""RptUK, acViewReport,,"[specFld]='" & fraOgrSpec & "'"

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    'not working' does not help us to help your - what happens - wrong result?, no result?, error? something else?

    looks like you are using an option group control so each option has to be assigned a value. You have 3 options, so you cannot use true/false because that only allows for 2 possible options.

    Beyond that, your design is hardcoded so if you add another country/region or spec you will need to modify everything - forms/reports/queries/code. It is also possible you only need one report and open with parameters to specify country/spec.

    Also recommend you get into the habit of giving your controls relevant names - Command127 could be anything and when you come to revisit your code down the line, you will spend a lot of time working out what is what. For example

    This is for the US button and when Spec1 is checked.
    so why are the arrows point to the UK? perhaps you have assigned the code to the wrong button?

  4. #4
    tomazm71 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    10
    Hi Ajax,

    Not working means one report opens but I want to have another report open when I change the selection on Option button to Spec2.
    How do I mark in VBA that:

    If Spec2 is marked/active/checked then run the specific report?

    Arrows point to UK just as an example.

    Thanks,
    Tom

  5. #5
    tomazm71 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    10
    Hi ranman256,

    I have created second option group and 1 button as you suggested.

    How do I set it from the beginning if I want to have those multiple checking on boxes and the report run accordingly ?

    Thanks,
    Tom
    Attached Thumbnails Attached Thumbnails ex2.jpg  

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    before going any further, please clarify - are you using an option group or are you using three option controls plus a box and label to look like an option group?

  7. #7
    tomazm71 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    10
    Two option groups and one button (Open Report) as Ajax suggested.
    What I really would like to know how do I write the code that when the combination of buttons from two different option groups is checked, the particular report is opened.

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    if you are using an option group, you need to use that control - each option will have a value which you will have specified, typically 1,2 and 3 - look at the properties for each option to check

    so you code would be something like

    Code:
    select case optiongroupname
        case 1
               docmd.openreport ….
         case 2
               docmd.openreport ….
         case 3
               docmd.openreport ….
    end select

  9. #9
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Here's a brute force method that works:

    Click image for larger version. 

Name:	frameOpt.JPG 
Views:	17 
Size:	17.3 KB 
ID:	35589

    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub cmdOpenReport_Click()
        Select Case fraOrgSpec.Value
            Case 1
                Select Case fraCountry.Value
                    Case 1
                        MsgBox "run report for spec1, UK"
                    Case 2
                        MsgBox "run report for spec1, US"
                    Case 3
                        MsgBox "run report for spec1, Canada"
                End Select
            Case 2
                Select Case fraCountry.Value
                    Case 1
                        MsgBox "run report for spec2, UK"
                    Case 2
                        MsgBox "run report for spec2, US"
                    Case 3
                        MsgBox "run report for spec2, Canada"
                End Select
            Case 3
                Select Case fraCountry.Value
                    Case 1
                        MsgBox "run report for spec3, UK"
                    Case 2
                        MsgBox "run report for spec3, US"
                    Case 3
                        MsgBox "run report for spec3, Canada"
                End Select
        End Select
    End Sub

  10. #10
    tomazm71 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    10
    Thanks everyone for quick and accurate advices. Everything works properly.

    Rgds,
    Tom

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 07-22-2017, 12:03 PM
  2. Option Buttons
    By Cyber27uk in forum Access
    Replies: 1
    Last Post: 01-10-2013, 03:45 PM
  3. Option buttons
    By Ecal in forum Programming
    Replies: 2
    Last Post: 11-11-2012, 09:04 AM
  4. Use of option group buttons
    By sireesha in forum Forms
    Replies: 1
    Last Post: 10-25-2012, 01:20 PM
  5. Option buttons
    By chazcoral2 in forum Forms
    Replies: 11
    Last Post: 09-13-2010, 07:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums