Results 1 to 14 of 14
  1. #1
    BED is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    26

    Command Button linked to Radio buttons

    Hello,

    Im on a form and i have multiple radio buttons to select different options. Each combo of radio buttons has a macro associated with it, but i want one command button to look at those buttons to make the decision of which macro to run.



    My second question is i want to relate radio buttons to one another... ex If radio button 1 is pushed then number 2 cant be pushed (or if number 2 is pushed, number one will become unpushed)

    Not sure if i need to start looking for code and messing around with that, or if i can build this button smart. Let me know... ( i can give Screenshots / whatever can help you help me)

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Have you looked at an option group? You can only select one of the options.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    BED is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    26
    Bingo, thats exactly what i was looking for. I would assume i can use If statements and else if statements on the button code to determine which macro to run.

    If option group1 value = 1 and if option group2 value = 2 and if option group3 value=1 then macro.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Either If/Then blocks or Select/Case, depending on the logic involved.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    BED is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    26
    Ok, thank you for your help, if i run into problems after i attempt to create this code would you mind if i posted it for some asistance?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Of course not; certainly post back if you get stuck.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    BED is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    26
    Hey im running into errors.... I think im on the right track.... let me konw what you think might be the issue.

    Code:
     
    Private Sub EXPORT_BUTTON_Click()
    On Error GoTo Err_ERROR
     
    If Frame95.Value = 1 And Frame108.Value = 1 And Frame114.Value = 1 Then
     
        DoCmd.RunMacro.Macro1
     
    ElseIf Frame95.Value = 1 And Frame108.Value = 1 And Frame114.Value = 2 Then
     
        DoCmd.RunMacro.Macro2
     
    ElseIf Frame95.Value = 1 And Frame108.Value = 2 And Frame114.Value = 1 Then
     
        DoCmd.RunMacro.Macro3
     
    ElseIf Frame95.Value = 1 And Frame108.Value = 2 And Frame114.Value = 2 Then
     
        DoCmd.RunMacro.Macro4
     
    ElseIf Frame95.Value = 2 And Frame108.Value = 1 And Frame114.Value = 1 Then
     
        DoCmd.RunMacro.Macro5
     
    ElseIf Frame95.Value = 2 And Frame108.Value = 1 And Frame114.Value = 2 Then
     
        DoCmd.RunMacro.Macro6
     
    ElseIf Frame95.Value = 2 And Frame108.Value = 2 And Frame114.Value = 1 Then
     
        DoCmd.RunMacro.Macro7
     
    ElseIf Frame95.Value = 2 And Frame108.Value = 2 And Frame114.Value = 2 Then
     
        DoCmd.RunMacro.Macro8
     
    End If
     
    ErrERROR:
        MsgBox ("You missed a step.....Try Again")
        End Sub
    Exit_sub:
        Exit Sub

    Thank you in advance for helping me.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What errors? For starters, you've reversed the error and exit points for your error trap. If you follow the code, you'll see that it will always execute the error message (there's nothing to direct code execution elsewhere). You also have the exit part after the End Sub, which means it's out there twisting in the wind, which will cause a compile error (probably something about invalid outside sub or something like that). Here's one proper structure of an error trap:

    http://www.baldyweb.com/ErrorTrap.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    BED is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    26
    Just to simplify things with my code i eliminated all error message and error coding. Its a very simple form, but i thought itd be cool to include an error msg box. No biggy removing it. My new code is as follows:

    Code:
     Private Sub EXPORT_BUTTON_Click()
     
    If Frame95.Value = 1 And Frame108.Value = 1 And Frame114.Value = 1 Then
     
        DoCmd.RunMacro.Macro1
     
    ElseIf Frame95.Value = 1 And Frame108.Value = 1 And Frame114.Value = 2 Then
     
        DoCmd.RunMacro.Macro2
     
    ElseIf Frame95.Value = 1 And Frame108.Value = 2 And Frame114.Value = 1 Then
     
        DoCmd.RunMacro.Macro3
     
    ElseIf Frame95.Value = 1 And Frame108.Value = 2 And Frame114.Value = 2 Then
     
        DoCmd.RunMacro.Macro4
     
    ElseIf Frame95.Value = 2 And Frame108.Value = 1 And Frame114.Value = 1 Then
     
        DoCmd.RunMacro.Macro5
     
    ElseIf Frame95.Value = 2 And Frame108.Value = 1 And Frame114.Value = 2 Then
     
        DoCmd.RunMacro.Macro6
     
    ElseIf Frame95.Value = 2 And Frame108.Value = 2 And Frame114.Value = 1 Then
     
        DoCmd.RunMacro.Macro7
     
    ElseIf Frame95.Value = 2 And Frame108.Value = 2 And Frame114.Value = 2 Then
     
        DoCmd.RunMacro.Macro8
     
    End If
     
    End Sub
    I get the error:
    Compile error:
    Arguement not optional

    and it highlights .RunMacro

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, didn't notice this the first time (though the other errors would have to have been fixed). You want

    DoCmd.RunMacro "Macro1"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    BED is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    26
    Works perfectly sir. thanks for you help.

    Just a thought.... If those are the only options i have (in the code above the 8 different macros...) Then cant i just make one more elseif that runs a msgbox that says you made an error.

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You'd probably want Else instead of ElseIf, since there really wouldn't be a condition to test for. You could have an Else catch any combination of choices that you hadn't accounted for (if any). Error traps are good to have because they catch unanticipated errors (what you've described I'd call an anticipated error). In a runtime environment, an error without error trapping will end the application, so error trapping makes the application more stable and user friendly.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    BED is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    26
    You are the man (i left the error message out, i totaly get what your saying but im so excited that my form works the error message got puched aside.)

    Thank you very much sir it is appreciated greatly.

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Moving Command Buttons
    By Pete Cope in forum Forms
    Replies: 0
    Last Post: 03-23-2010, 03:21 PM
  2. option group radio buttons
    By ManC in forum Forms
    Replies: 9
    Last Post: 03-08-2010, 03:46 AM
  3. Access 2007 Command Buttons
    By fgerald in forum Access
    Replies: 2
    Last Post: 03-05-2010, 07:09 PM
  4. Select Radio Button and another one turns off
    By Lockrin in forum Programming
    Replies: 1
    Last Post: 02-09-2010, 02:17 PM
  5. Open a linked subform with a command button
    By flablueeyedblond in forum Forms
    Replies: 0
    Last Post: 11-18-2005, 01:18 PM

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