Results 1 to 4 of 4

Thread: Validating Data

  1. #1

    Thread Starter
    New Member StacyStacy's Avatar
    Join Date
    Jul 2003
    Location
    In the South. Can you believe it??
    Posts
    11

    Validating Data

    I have written some code to do the following:

    When keying data into a new record and/or clicking onto the "Menu" button, which closes the form.

    The User must enter a 3-digit Project Code (text field). If the project code contains a null value, a message appears stating they must enter a 3-digit project code. If the Project code is less than 3 digits, another message appears stating that the Project Code must be 3 digits.

    If the user does not enter the 3-digit code or leaves the Provider Code field blank, I want the message box to appear and the cursor placed again in the Provider Code field. If the User enters a 3-digit code, then I want the cursor to be placed in the "Fed Tax ID" field.

    ***************************

    Here's my code placed in the "After Update" and "Lost Focus" of the Provider Code field:

    Private Sub Provider_Code_AfterUpdate()
    If IsNull(Me!Provider_Code) Then
    MsgBox "This Field, 'Provider Code' Must Be Completed. Please Enter A 3-Digit Privider Code!", vbExclamation
    Provider_Code.SetFocus
    Cancel = True
    End If

    If Len(Me.Provider_Code) < 3 Then
    MsgBox "Please Enter A 3-Digit Privider Code!"
    Else: Me.Provider_Code.SetFocus
    End If

    If Len(Me.Provider_Code) > 3 Then
    Me.Fed_Tax_ID__.SetFocus
    Else
    End If

    End Sub

    *****************
    Here's my code placed in the "After Update" of the "Form":

    Private Sub Form_AfterUpdate()
    If IsNull(Me!Provider_Code) Then
    MsgBox "This Field, 'Provider Code' Must Be Completed. Please Enter A 3-Digit Privider Code!", vbExclamation
    Provider_Code.SetFocus
    Cancel = True
    End If
    End Sub


    It somewhat works. The messages appears, but the cursor is not placed into the Project Code field if there is a null value or less than 3 digits entered.


    Please help. Thanks.

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    Put all your setfocus code before your MsgBox code.

  3. #3

    Thread Starter
    New Member StacyStacy's Avatar
    Join Date
    Jul 2003
    Location
    In the South. Can you believe it??
    Posts
    11
    That didn't work. What should I do now?

  4. #4
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    Why don't you do something like.....

    Code:
    Sub Provider_Code_AfterUpdate() 
    If txtProvider_Code = "" Then 
    txtProvider_Code.SetFocus
    MsgBox "This Field, 'Provider Code' Must Be Completed. Please Enter A 3-Digit Privider Code!", vbExclamation 
    End If 
    
    If Len(txtProvider_Code) < 3 Then 
    txtProvider_Code.SetFocus 
    MsgBox "Please Enter A 3-Digit Privider Code!" 
    End If 
    
    If Len(txtProvider_Code) > 3 Then 
    txtFed_Tax_ID__.SetFocus  
    End If 
    
    End Sub 
    
    Sub Form_AfterUpdate() 
    If txtProvider_Code = "" Then 
    txtProvider_Code.SetFocus
    MsgBox "This Field, 'Provider Code' Must Be Completed. Please Enter A 3-Digit Privider Code!", vbExclamation 
    End If 
    End Sub

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