Results 1 to 3 of 3

Thread: Validate() event ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    3
    What is the significance of Validate() event in VB? Can you please specify an example as to where this event can be used?

    In the programs I have created, I have written the validations in the Change() and KeyPress() events in case of text fields and in Click() event in case of buttons. So, where does the Validate() event fit in?

    Anna

  2. #2
    New Member
    Join Date
    Mar 2000
    Location
    Kamloops BC Canada
    Posts
    7

    Validate event

    Hi

    As a single example, you can use it in conjunction with bound (to a .mdb in this case) textboxes and a data control (where you don't allow the user access to the data control itself)

    It uses the datControl functions to fire the validate event.

    e.g.

    '****************************************************
    ' Purpose: To validate input and display message
    '****************************************************
    Private Sub datControl_Validate(Action As Integer, Save As Integer)

    Dim pstrmessage As String
    Dim pintReturn As Integer

    If Action = vbDataActionUpdate Then
    If txtCatagory.Text = vbNullString Or txtDescription.Text = vbNullString _
    Or txtSalesUnit.Text = vbNullString Then
    pstrmessage = "Required field -You must enter a value"
    Action = vbDataActionCancel
    End If

    If Not IsDate(txtLastInventory.Text) Then
    pstrmessage = "Invalid Date - Date format is " & Date
    Action = vbDataActionCancel
    End If

    If Action = vbDataActionCancel Then
    pintReturn = _
    MsgBox(pstrmessage, vbOKOnly, "Input error")
    End If
    End If

    End Sub



    Dave



  3. #3
    Lively Member
    Join Date
    Mar 2000
    Posts
    82
    the validate event does just that. it fires before the lost focus event to give you a chance to validate and cancel the shift of focus if need be. It is used with the causesvalidation property. if causesvalidation is set to true(the default), when this control is about to gain focus it will cause the validate event of the control that is losing the focus to fire. You can then validate and if you need to, cancel the shift of focus. I shows some strange behavior at times so you should experiment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width