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:
'Here is the text box validate routine on my form 'Customer is the name of the class object I am using Private Sub txtField_Validate(Index As Integer, Cancel As Boolean) On Error GoTo ValidationError Select Case Index Case FirstName Customer.FirstName = txtField(FirstName).Text Case MI Customer.MI = txtField(MI).Text Case LastName Customer.LastName = txtField(LastName).Text Case Spouse Customer.Spouse = txtField(Spouse).Text Case Address Customer.Address = txtField(Address).Text Case City Customer.City = txtField(City).Text Case StateProv Customer.StateProv = txtField(StateProv).Text Case ZipPostal Customer.ZipPostal = txtField(ZipPostal).Text Case PhoneNumber1 Customer.PhoneNumber1 = txtField(PhoneNumber1).Text Case PhoneNumber2 Customer.PhoneNumber2 = txtField(PhoneNumber2).Text Case Comments Customer.Comments = txtField(Comments).Text Case Else End Select Exit Sub ValidationError: MsgBox Err.Number & " " & Err.Description txtField(Index).SetFocus End Sub 'Here is an example of a set property in my Customer class Public Property Let FirstName(vData As String) If Len(vData) > 20 Then Call Err.Raise(vbObjectError + 1, "First name exceeds the maximum length for this field") Else mFirstName = vData End If End Property




Reply With Quote