Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handling errors on a user form

Status
Not open for further replies.

donjohnson

Programmer
Jun 23, 2004
53
Hello!
I would like to call a subroutine to set errors for a user form, passing the field name in error and the related error message. Can you tell me if this is possible?

For example, instead of coding for each field:
Code:
    iErrCt = iErrCt + 1
    strErrMsg(iErrCt) = "This is the error message" 
    EntryForm.fLocMH.SetFocus
    EntryForm.fLocMH.BackColor = lErrColor

I would like the subrtn to look like:
Code:
    iErrCt = iErrCt + 1
    strErrMsg(iErrCt) = parm-err-msg
    EntryForm.parm-fld-name.SetFocus
    EntryForm.parm-fld-name.BackColor = lErrColor
and then on the edit, only call the subroutine with parms.

Also, is there any way to make a field numeric input only in the form textbox properties, rather than pass it to the VBA code to trip an error? Or - how would you define a field to be numeric and > 0?

Thanks!

Don
 
Hi Don
I'm not sure about the first part of your problem but here is one way of dealing with the input to the textbox by trapping the user input. Values will be >0 by default as the "-" is not allowed

Code:
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not ((KeyAscii >= 47 And KeyAscii <= 57) Or KeyAscii = 46) Then
    'allows 0 to 9 & dot (.)
    KeyAscii = 0
End If
End Sub

;-)

If a man says something and there are no women there to hear him, is he still wrong? [ponder]
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top