Results 1 to 5 of 5
  1. #1
    wasim_sono is offline Advanced Beginner
    Windows XP Access 2013 64bit
    Join Date
    May 2005
    Location
    Pakistan
    Posts
    73

    Validation rule for a text field

    What will be the validation rule for a text value that shouln not be empty.



    Meaning that a user should must be enter some text or date in the field. If empty than a message will appear.

    I used "required" option in the table design mode but it works entire record and after completing one record this message appear. I want it on the field level. for a numeric field I used the following validation rule.

    > 0

    but i can't imagine that for a text or date field what will be the rule?

    Wasim

  2. #2
    Join Date
    Dec 2005
    Location
    Wilmington, DE - USA
    Posts
    275
    Wasim,

    I would use the Form's BeforeUpdate event to test if the textbox is empty, and if it is:

    1. Set the sub's Cancel argument to True (to cancel the update)
    2. Set the focus on that textbox
    3. Show a MsgBox telling the user s/he must make an entry in that textbox

  3. #3
    wasim_sono is offline Advanced Beginner
    Windows XP Access 2013 64bit
    Join Date
    May 2005
    Location
    Pakistan
    Posts
    73
    Hi Patrick

    Nice to see u. I used the following code.

    If isnull([Field name]) then
    Msgbox" "
    Me.Fieldname.set focus
    End if

    But gives error on 3rd line. Pl. tell how to insert cancel so the cursor got focus in same field.

    I also asked about sub form in this forum but still not replied. Will u help me for these topics?

    If it is possible that when a user finished its work an exit the application and next day when he opens the form the last day entries fetched up in the form.

    Thanks.

  4. #4
    Join Date
    Dec 2005
    Location
    Wilmington, DE - USA
    Posts
    275
    Wasim,

    Try something like:

    Code:
    If IsNull(Me![FieldName]) Then
        MsgBox "You cannot leave Field X blank!"
        Cancel = True
        Me.[FieldName].SetFocus
    End If
    Make sure that you are getting FieldName correct!

  5. #5
    wasim_sono is offline Advanced Beginner
    Windows XP Access 2013 64bit
    Join Date
    May 2005
    Location
    Pakistan
    Posts
    73
    Dear Patrick

    Thanks for a reply. I'm using the following code but the control not getting the focus on that field but forward on next field.

    Code:
    If IsNull([EmpNo]) Then
        MsgBox "Field can't be empty"
        Cancel = True
        Me.[EmpNo].SetFocus
    End If
    Thanks.

    Wasim

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Validation Rule: Date
    By krymer in forum Access
    Replies: 0
    Last Post: 08-27-2008, 03:30 PM
  2. Validation on identical text question
    By edrahl in forum Database Design
    Replies: 1
    Last Post: 02-26-2008, 09:38 AM
  3. Split text field into two text fields
    By Grant in forum Access
    Replies: 6
    Last Post: 01-31-2008, 05:52 AM
  4. Validation Rule
    By mistaken_myst in forum Database Design
    Replies: 2
    Last Post: 10-29-2007, 02:08 PM
  5. Field Level Date validation
    By fadone in forum Forms
    Replies: 1
    Last Post: 12-09-2005, 10:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums