Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

how to automatically put a label when i click an option button?

Discussion in 'Information Technology' started by Last user''''s name that modified a reco, Nov 5, 2005.

  1. hi. greetings!

    i have an employee database and i have an option group called "Employee
    Status" and a label called lblStatus. Now, what I want to do is to display
    into the lblStatus the option I selected from the option group. For example,
    when I select "AWOL" from the option group, lblStatus should display "AWOL".
    Please help me.

    Thank you very much!

    Resty
     
  2. Loading...


  3. Sprinks

    Sprinks
    Expand Collapse
    Guest

    Hi.

    Set the Label's caption property in the Option Group's AfterUpdate and the
    Form's OnCurrent events. Note that the value of the option group is
    different than the label of the selected option.

    Select Case Me![YourOptionGroup]
    Case 1
    Me![YourLabel].Caption = "AWOL"
    Case 2
    Me![YourLabel].Caption = "SomeOtherValue"
    ' Place other cases here
    Case Else
    Me![YourLabel].Caption = ""
    End Select

    Hope that helps.
    Sprinks

    "Last user''''s name that modified a reco" wrote:

    > hi. greetings!
    >
    > i have an employee database and i have an option group called "Employee
    > Status" and a label called lblStatus. Now, what I want to do is to display
    > into the lblStatus the option I selected from the option group. For example,
    > when I select "AWOL" from the option group, lblStatus should display "AWOL".
    > Please help me.
    >
    > Thank you very much!
    >
    > Resty
     
  4. WhyIsDoug

    WhyIsDoug
    Expand Collapse
    Guest

    As with anything else in VBA/Access there are several ways to accomplish
    this. I always prefer to make the code as dynamic as possible so anytime I
    can make the code figure it out without me altering it when I add new options
    that's what I would do.

    In that vain I would suggest that you add the Status ("AWOL" in your
    example) to the Tag property of the Option Button when you add the control to
    the Option Groug. Then you can simply loop through the Controls collection of
    the Option Group looking for OptionButton controls. Test there OptionValue
    property against that of the OptionGroup and then set the Caption of your
    Status Label to the Tag property of the Option Button selected.

    Here's an example:

    Private Sub opgStatus_AfterUpdate()
    Dim ctl As Control

    For Each ctl In opgStatus.Controls
    If TypeOf ctl Is OptionButton Then
    If Me.opgStatus.Value = ctl.OptionValue Then
    Me.lblStatus.Caption = ctl.Tag
    Exit For
    End If
    End If
    Next opbButton

    Set ctl = Nothing

    End Sub

    As you can see, you can now simply add OptionsButton's to the OptionGroup,
    put the Status you want in the Tag property of the OptionButton and the code
    will continue to work without modification.

    This would work well (or even better) if you used a table of status' to
    dynamically build the OptionGroup using the Status ID as the OptionValue. Of
    course if you reach this point, a different control (such as a ListBox or
    ComboBox) would probably work better.

    If this answered your question please respond accordingly when asked. THis
    will mark it as an answer and allow others to find it more easily.
    --
    WhyIsDoug?


    "Last user''''s name that modified a reco" wrote:

    > hi. greetings!
    >
    > i have an employee database and i have an option group called "Employee
    > Status" and a label called lblStatus. Now, what I want to do is to display
    > into the lblStatus the option I selected from the option group. For example,
    > when I select "AWOL" from the option group, lblStatus should display "AWOL".
    > Please help me.
    >
    > Thank you very much!
    >
    > Resty
     
  5. RE: how to automatically put a label when i click an option button

    hi, Sprinks!

    Your code worked well. Thank you so much, dude!

    Resty

    "Sprinks" wrote:

    > Hi.
    >
    > Set the Label's caption property in the Option Group's AfterUpdate and the
    > Form's OnCurrent events. Note that the value of the option group is
    > different than the label of the selected option.
    >
    > Select Case Me![YourOptionGroup]
    > Case 1
    > Me![YourLabel].Caption = "AWOL"
    > Case 2
    > Me![YourLabel].Caption = "SomeOtherValue"
    > ' Place other cases here
    > Case Else
    > Me![YourLabel].Caption = ""
    > End Select
    >
    > Hope that helps.
    > Sprinks
    >
    > "Last user''''s name that modified a reco" wrote:
    >
    > > hi. greetings!
    > >
    > > i have an employee database and i have an option group called "Employee
    > > Status" and a label called lblStatus. Now, what I want to do is to display
    > > into the lblStatus the option I selected from the option group. For example,
    > > when I select "AWOL" from the option group, lblStatus should display "AWOL".
    > > Please help me.
    > >
    > > Thank you very much!
    > >
    > > Resty
     

Share This Page