Hi,

In my form I have a textbox validate routine that calls the individual sets of a class module, which check the data to ensure it is within the field size limits of the database. If the data is too long, I want to raise an error and pass this back to the textbox Validate routine so I can trap the error there. Currently, the program crashes in the Class in the Set properties when the data is too big. How do I pass this error back to the form??? I've included all the code below.

VB Code:
  1. 'Here is the text box validate routine on my form
  2. 'Customer is the name of the class object I am using
  3.  
  4. Private Sub txtField_Validate(Index As Integer, Cancel As Boolean)
  5.     On Error GoTo ValidationError
  6.    
  7.     Select Case Index
  8.         Case FirstName
  9.             Customer.FirstName = txtField(FirstName).Text
  10.         Case MI
  11.             Customer.MI = txtField(MI).Text
  12.         Case LastName
  13.             Customer.LastName = txtField(LastName).Text
  14.         Case Spouse
  15.             Customer.Spouse = txtField(Spouse).Text
  16.         Case Address
  17.             Customer.Address = txtField(Address).Text
  18.         Case City
  19.             Customer.City = txtField(City).Text
  20.         Case StateProv
  21.             Customer.StateProv = txtField(StateProv).Text
  22.         Case ZipPostal
  23.             Customer.ZipPostal = txtField(ZipPostal).Text
  24.         Case PhoneNumber1
  25.             Customer.PhoneNumber1 = txtField(PhoneNumber1).Text
  26.         Case PhoneNumber2
  27.             Customer.PhoneNumber2 = txtField(PhoneNumber2).Text
  28.         Case Comments
  29.             Customer.Comments = txtField(Comments).Text
  30.         Case Else
  31.        
  32.     End Select
  33.    
  34.     Exit Sub
  35.    
  36. ValidationError:
  37.    
  38.     MsgBox Err.Number & " " & Err.Description
  39.     txtField(Index).SetFocus
  40. End Sub
  41.  
  42. 'Here is an example of a set property in my Customer class
  43.  
  44. Public Property Let FirstName(vData As String)
  45.     If Len(vData) > 20 Then
  46.         Call Err.Raise(vbObjectError + 1, "First name exceeds the maximum length for this field")
  47.     Else
  48.         mFirstName = vData
  49.     End If
  50. End Property