Results 1 to 3 of 3
  1. #1
    Ecal is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    2

    Unhappy Option buttons

    Hello, All


    I am trying to create two option buttons Option32 and Option34 what I would like to happen is if both are clicked making them -1 a message to pop up and tell the user to choose either optionbutton not both. Then once the ok button displayed at the bottom of the message is pressed it resets both Option34 and Option32 to 0 or False respectively. However when just Option32 is choosen it pulls up another form to fill out. This is what I have thus far........ Have not gotten to the form part still kind of new to programming in visual basic so any help would be greatly appreciated. Thanks in Advance.

    Private Sub Option32_AfterUpdate()
    If Option34.Value = -1 & Option32.Value = -1 Then

    Dim Msg, Style, Title, Help, Ctxt, Response
    Msg = "Can not have both options chosen. Click Yes or No" ' Define message.
    Style = vbOKOnly + vbCritical + vbDefaultButton1 + vbApplicationModal
    ' Define buttons.
    Title = "Error" ' Define title.
    Help = "DEMO.HLP" ' Define Help file.
    Ctxt = 1000 ' Define topic
    ' context.
    ' Display message.
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbOKOnly Then ' User chose Yes.

    Me.Option32.Value = 0
    Me.Option34.Value = 0
    End If
    End If


    End Sub

    Not sure where I am going wrong compiled and everything but in the view form when I go to test it does not work.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If you put the option buttons in an Option Group control, then only one can be selected.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As June7 said, creating an Option Group for your buttons will allow the Access Gnomes to do all of the heavy lifting for you! In Form Design View:

    1. Click on the Option Group Icon and place on Form (Under the Design Tab on the Ribbon)
    2. Follow the Wizard and enter the Caption for each Button
    3. Hit 'Next'
    4. Select "No, I don't want a Default'
    5. Hit 'Next'
    6. Hit 'Next' (Yes, hit it a second time to accept the Given Values)
    7. 'Option Buttons' is the Default type of Control, so hit 'Next' again
    8. Enter the Caption you want to appear above the Option Group
    9. Hit 'Finish'


    Now, to use the option that is chose, something like this:
    Code:
    Private Sub Frame0_AfterUpdate()
     Select Case Me.Frame0
      Case 1
        'Code goes here for when the first button is selected
       Case 2
        'Code goes here for when the second button is selected
     End Select
    End Sub


    Replace Frame0 with the actual name Access assigns to the Option Group; it will be 'Frame' followed by one or more digits.

    Place whatever code you want to run when each button is selected in the designated place under the 'Cases.'

    Access will now only allow one Option to be selected from the Group.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Use of option group buttons
    By sireesha in forum Forms
    Replies: 1
    Last Post: 10-25-2012, 01:20 PM
  2. How too use check boxes and option buttons
    By newtoAccess in forum Forms
    Replies: 0
    Last Post: 12-03-2010, 04:41 PM
  3. Option buttons
    By chazcoral2 in forum Forms
    Replies: 11
    Last Post: 09-13-2010, 07:53 AM
  4. option group radio buttons
    By ManC in forum Forms
    Replies: 9
    Last Post: 03-08-2010, 03:46 AM
  5. VBA Code in Access w/ option buttons
    By WebKiid in forum Access
    Replies: 1
    Last Post: 07-16-2009, 12:20 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