Error handling

  • Thread starter Thread starter Jim Lavery
  • Start date Start date
J

Jim Lavery

Does anyone know the VB code in excel to produce an error message if the
code breaks down. For example if the user doesn't select from a drop down
list it tells them to "Select from the list"
 
Does anyone know the VB code in excel to produce an error message if the
code breaks down. For example if the user doesn't select from a drop down
list it tells them to "Select from the list"

Hi Jim,

You seem to be talking about two different things here. The example
you use is actually Validation, which is generally used to prevent
errors from happening. Handling an error after it has happened is a
different matter.

Which of the two are you actually seeking help on and can you expand
the context a little. What are trying to do and do you have some
example code you can post?

Br, Nick.
 
I have 2 command buttons The first prints the complete IT plan of the
building (About 30 pages)
The second asks the user to select from a drop down list the floor & wing &
prints that 1 page.

If the user doesn't select the Floor/wing but selects that command the code
breaks down. If I put in an On error message to handle the error it then
gives the message but then goes on to print the 30 pages.





Does anyone know the VB code in excel to produce an error message if the
code breaks down. For example if the user doesn't select from a drop down
list it tells them to "Select from the list"

Hi Jim,

You seem to be talking about two different things here. The example
you use is actually Validation, which is generally used to prevent
errors from happening. Handling an error after it has happened is a
different matter.

Which of the two are you actually seeking help on and can you expand
the context a little. What are trying to do and do you have some
example code you can post?

Br, Nick.
 
I have 2 command buttons The first prints the complete IT plan of the
building (About 30 pages)
The second asks the user to select from a drop down list the floor & wing&
prints that 1 page.

If the user doesn't select the Floor/wing but selects that command the code
breaks down. If I put in an On error message to handle the error it then
gives the message but then goes on to print the 30 pages.

Not sure if your command buttons are on a sheet or a form, either way
it seems odd that the user would need to click a button to be asked to
select from a dropdown list.

A better way might be set your 'Print' command button's 'Enabled'
property to FALSE at design time and have the dropdown (rather than
another command button) clearly labelled 'Select Floor/Wing:' Then, in
the dropdown's change event, test the length of the dropdown's text or
value property. If it's greater than 0 then you set the Print button's
enabled property to TRUE otherwise you set it to FALSE (even though
you set it to FALSE at design time you still need to set it to FALSE
after finding a zero length string in case the user entered a value
then deleted it).

This is just a loose overview of how you might tackle the problem. If
you need more help you'll need to specify whether these command
buttons and dropdown are on a VBA Form or a sheet (or a mixture).

Br, Nick.
 
Back
Top