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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Control (VB 6) - Which events fire and when ?

Status
Not open for further replies.

JohnBates

MIS
Feb 27, 2000
1,995
0
0
US
Hi VB pros -

I'm using the Data Control to build a program for simple table maint (add/change/delete). Yeah, I know but in this case, the data control is just what is needed.

But before the record gets changed/written I need to add some custom code to do some validation, check what was entered and throw up the usual 'Are you sure...?' msgbox.

Just how do you find out where to insert your custom code?
Using VB 6

Thanks, John
 
I'm thinking that you wish to validate before you allow access to save. Use the Validate procedure for this. The following is an example...

Private Sub txtMovieNumber_Validate(Cancel As Boolean)
If Len(txtMovieNumber) > 4 Then
ErrorMessage = "The movie number cannot contain more than 4 characters. Please Re-enter."
Message = MsgBox(ErrorMessage, vbCritical, "Incorrect Entry")
txtMovieNumber.Text = ""
txtMovieNumber.SetFocus
Cancel = True
Else
If Not CanChangeMovieNumber And Trim(txtMovieNumber.Text) <> PreviousMovieNumber Then
ErrorMessage = &quot;The movie number cannot be changed.&quot; & Chr(13)
ErrorMessage = ErrorMessage + &quot;If you have entered the incorrect movie number, delete the record and re-enter the record.&quot;
txtMovieNumber.Text = PreviousMovieNumber
Message = MsgBox(ErrorMessage, vbCritical, &quot;Cannot Enter Here&quot;)
Cancel = True
End If
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top