Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    May 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    combobox errorhandling (Office2K)

    Hi,

    I've made a combobox on a form. Default it shows a helptext (like 'Choose year'). This is, of course an invalid choice, so I need to trap this choice with an errorhandler. Unfortunately the choice is legitimate in VBA (listindex =0) so i cannot use an errorhandler for this. Or am I mistaken? Could I raise an error? How do I do this?

    Thanks in advance,

    Paul

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: combobox errorhandling (Office2K)

    Why don't you remove the help text as an item and set the ControlTipText property of the combo box to the help text? The help text will be displayed as the user moves the mouse pointer over the combo box.

  3. #3
    New Lounger
    Join Date
    May 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: combobox errorhandling (Office2K)

    Hans,

    The trouble is that I need to be absolutely sure that the user makes the correct choice. The choice in the combobox is part of a directory path that the user will open. When they choose the wrong one (If i follow your idea when they make no choice, they will automatically get the first value) a lot of documents will open and this will not be obvious. This macro will generate examforms: it is quite important that we make correct documents.

    So, is it possible to trap the choices in a combobox with an errorhandler? I need the 'resume' command (or an equivalent) to be able to let the user make a correct choice. My code now generates a 'resume without error' failure.

    Thanks in advance,

    Paul

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: combobox errorhandling (Office2K)

    You wrote "I've made a combobox on a form". Do you mean that your document is a form, or that you have created a userform in the Visual Basic Editor?

  5. #5
    New Lounger
    Join Date
    May 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: combobox errorhandling (Office2K)

    Hans,

    Yes, I've made a userform in the VBA editor. The combobox is filled in this way:

    Me.CboCohort.AddItem "Kies Cohort"
    Me.CboCohort.AddItem "2005"
    Me.CboCohort.AddItem "2006"
    Me.CboCohort.AddItem "2007"
    Me.CboCohort.AddItem "2008"

    If tried to trap the error with an if... then statement, (f me.cbocohort.listindex = 0 then msgbox etc etc) but when you click 'ok' in the messagebox the code runs on, still creating an error. The return from the combobox is used to set a directorypath (U:2005...) Of course the directory 'kies cohort' doesn't exist.

    Any suggestions?

    Thanks,

    paul

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: combobox errorhandling (Office2K)

    Let's say that you have a command button cmdOK on the userform. The On Click event procedure for the button could look like this:

    Private Sub cmdOK_Click()
    If Me.cboCohort.ListIndext = 0 Then
    MsgBox "Please select a year.", vbInformation
    Me.cboCohort.SetFocus
    Exit Sub
    End If
    ' Code continues here if user selected a year
    ...
    End Sub

    The line Exit Sub ensures that the code doesn't continue if the user didn't select a year.

  7. #7
    New Lounger
    Join Date
    May 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: combobox errorhandling (Office2K)

    Hans,

    That's it!

    Thank you,

    Paul

Posting Permissions

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