Senin, 08 Juni 2015

Re: [MS_AccessPros] Data Validation

 

OK, ran a little test, and this code works:


Private Sub Form_Error(DataErr, Response)

    If DataErr = 2113 Then
        MsgBox "Whatever you want to tell the user here…"
        ' Clear the edit
        Me.Undo
        ' Tell Access we handled the error
        Response = acDataErrContinue
    End If
End Sub

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Jun 9, 2015, at 8:42 AM, John Viescas JohnV@msn.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

Dear spears-

I assume you're using a form for data entry.  If the Serial Number is defined a numeric, Access won't let the user save non-numeric info in the field, but it will pop up an error message.  You can do two things:

1) Use the control's Before Update event procedure to test the value before it gets saved in the field and reject it and clear it (using Me.Undo).

2) Use the form's Error event procedure to catch cases where the Before Update doesn't trap the error.  You can look at the DataErr parameter to determine the type of error (2113 should be the error code generated by Access when you try to enter alpha in a numeric field), put up your own error message and clear the field.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Jun 8, 2015, at 11:40 PM, spearse@sfsu.edu [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

Working on building a table in Access that will contain only two fields: 1) Asset Tag Number and 2) Serial Number.  The "Asset Tag Number" is always a six- (6) digit number; whereas, the "Serial Number" is always alphanumeric.  Both fields will be inputted via a barcode scanner. 

 

Two questions:

 

1)      1. How do I set up a data validation so the Asset Tag Number cannot be accidently scanned into the Serial Number field? (Already set validation for the Asset Tag Number)


2)      2. In the case that an error message appears, can Access be setup to clear the field after the "OK" button is clicked upon reading the message?

 

If you need more information to help you answer my question – please do not hesitate to ask me.

 

Just a note: I am a green Access user.

 

Thanks!




__._,_.___

Posted by: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (5)

.

__,_._,___

Tidak ada komentar:

Posting Komentar