Consulting

Results 1 to 6 of 6

Thread: Solved: ActiveX ComboBox problem

  1. #1

    Solved: ActiveX ComboBox problem

    I have a document with a table that has Active X combobox dropdowns and text boxes. Everything works great – my problem is when I reset the combobox – the MsgBox window displays twice when I include the following
    Cbo_harm1.Value = “”
    The code does what I want it to changes the combobox to "", but I don’t want the message box to be displayed twice which makes the user to select ok twice. If I do not include the Cbo_harm1.Value then it only displays once but does not reset the combobox. Can someone tell me why it is populating the MsgBox twice.

    This is how I have the fields set up:
    Probability text box, Harm combobox, Severity text box and a Final Risk textbox.

    First text box (Probability) the user inputs a number, the next field is a combobox
    (Harm) user chooses from the dropdown list. (I have code for the Harm combobox that if the users chooses Harm One then the Severity field will populate the number 1; Harm Two then the Severity will be 2 on and on… )
    Once they have chosen the harm dropdown the severity field will populate and then another text box titled Final Risk will calculate the data from the two text boxes (Probability and Severity) – see below.

    Example: Final Risk = Probability X Severity

    Everything works great, but I am wanting the user to input in the first textbox (Probability) and next the combobox Harm - and it they do not input in the Probability field first - I have added code that “cbo_harm_Change() to display a message window stating that they need to input data in the Probability field, and then the combobox will change to equal “”
    I can’t use the clear because on “Document open” I populate the list and do not want to lose that list.

    Change Event Code: (I shortened up the code it does not include all of the If statements)

    Sub cbo_harm_Change()
    If txt_probability1.Text = "" Then
    Application.ScreenUpdating = False
    MsgBox "You must input a total for Initial Probability of Occurrence before selecting a Harm.", , "ERROR - Message"

    cbo_harm1.Value = ""
    txt_severity1.Value = ""
    txt_initial_risk1.Value = ""
    Exit Sub
    Else

    If cbo_harm1.Value = "Corneal Edema" Then
    txt_severity1.Value = "3"
    End If
    End If
    End Sub

    Looking forward to hearing back and thank you for your help.

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    The _Change event fires when the control changes.

    In this case, you want to consider trying _Enter to check back against the textbox.

    Why does it show the message twice? Assuming of course txt_probability1.Text = "", then:

    Say cbo_harm is - right NOW - "Harm One".

    It is changed to "Harm Two". _Change fires. In this case, because txt_probability1.Text = "", there is an instruction to...change it a second time. This fires _Change again after the first firing terminates.

  3. #3
    Thanks for your reply but I am not sure what you mean by the following:

    In this case, you want to consider trying _Enter to check back against the textbox.
    How do I do that?

    I really want the code to not display the MsgBox twice that is very annoying. Is there anyway to not have it do that.
    Again thanks.

  4. #4
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "Is there anyway to not have it do that. "

    I will repeat. In this case, try using _Enter, not _Change.

    "How do I do that?"

    It is a Sub, just like _Change is a Sub.

    Sub cbo_Harm_Enter()

    Are you aware of the dropdowns in code modules? They are at the top. The left dropdown lets you choose the object (e.g. cbo_Harm).

    The right dropdown lets you choose all the events available for that object.

    AfterUpdate
    BeforeDragOver
    BeforeDropOrPaste
    BeforeUpdate
    Change
    Click
    DblClick
    DropButtonClick
    Enter
    Error
    Exit
    KeyDown
    KeyPress
    KeyUp
    MouseDown
    MouseMove
    MouseUp

    These are the events avilable to you for a combobox on a userform.

  5. #5
    Thanks for the explanation. I knew about the other events but I have always just used the change event. I also did try the enter but it did not do what I was wanting.
    I did find my answer and even though you did not give me the answer I wanted - you did help me to figure out what I needed. So again thanks for your help.
    All I needed to use was the click event. It does not fire twice and does what I am needing.

  6. #6
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Oh well, _Click will do.

    Actually, it is rather instructive if you put messageboxes (e.g. "From the _Enter event.", "From the _Click event.", "From the _Change event.") into a bunch of events.

    I can pretty much guarantee you will see surprising things.

Posting Permissions

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