PDA

View Full Version : stop errors on a user form



ashgull80
10-21-2016, 04:19 AM
Hi

Im sure ive seen alot of people do this but i am a complete noivce with vba so not sure where to start.

my issues are that i have a userform that i use to input data to a sheet.

firstly i pick a job number from a database sheet either from a dropdown box or typing into the dropdown box, if i type in the dropdown box and i accidently type a number that is not on the database list i get a 'runtime error 91'

secondly i have a textbox that i input a date into, likewise if im typing a date and i input it incorrectly i get a 'runtime error 13' type mismatch.

i completly uinderstand why these errors occur but what i would like to do is instead of the error function i would like a small error message that pops up but can then be closed to rectify the issue rater than having the error handling box pop up and then ending so the userform unloads and need to start from the beginning.

I hope that all makes sense and i lookforward to some help/advice.

thanks ash

SamT
10-21-2016, 06:01 AM
Use the Go Advanced Option to upload a sample Workbook with all proprietary and personal information redacted. If there is a lot of data on it, please delete all but a few rows.

And, PLEASE, close Excel after saving the sample book BEFORE uploading it.

mana
10-21-2016, 06:06 AM
1) you can use matchrequired property


2)

Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsDate(TextBox1.Text) Then
MsgBox "Incorrect data!"
TextBox1.Text = ""
Cancel = True
End If
End Sub