|
-
March 9th, 2010, 01:17 AM
#1
Validation
Hi,
I would like to perform a validation check on a field (Employee/Staff Number) there should not be duplicate entries in this field so i would like for a check to be performed when the next field is clicked then a msg displayed saying "Staff Number already exists"
Any sample code would be appreciated
Regards
-
March 9th, 2010, 01:52 AM
#2
Re: Validation
Typically this would be done with a lookup query assuming that your data is stored in a database.
-
March 9th, 2010, 02:57 AM
#3
Re: Validation
yes my data is in an access database, any code in mind?
-
March 9th, 2010, 06:49 AM
#4
Re: Validation
If in your access table the field is an index field with no duplicates, you can proceed like this:
Try to write the record to the table. If the entry is a duplicate the write will be rejected, returning an error code (or even throw up an error). You can trap this error and write an apropriate reaction like a messagebox saying "no duplicates".
-
March 9th, 2010, 08:33 AM
#5
Re: Validation
Correct. This needs to be handled through the database. Full stop.
-
March 10th, 2010, 09:23 AM
#6
Re: Validation
 Originally Posted by RussKass
Hi,
I would like to perform a validation check on a field (Employee/Staff Number) there should not be duplicate entries in this field so i would like for a check to be performed when the next field is clicked then a msg displayed saying "Staff Number already exists"
Any sample code would be appreciated
Regards
First of all you should try to write some code, based on your requirement and if you get struck in between , there are many gurus in this forum to guide.
Code:
Private Sub txtempNo_Validate(Cancel As Boolean)
Dim TmpRs As New ADODB.Recordset
TmpRs.Open "Select EmpNo From EmpDetails Where EmpNo=" & txtempNo.Text, Conn, adOpenDynamic, adLockBatchOptimistic
If Not TmpRs.EOF Then
MsgBox "Staff Number already exists"
Cancel = True
End If
End Sub
Last edited by ComITSolutions; March 10th, 2010 at 09:36 AM.
Encourage the efforts of fellow members by rating
Lets not Spoon Feed and create pool of lazy programmers
- ComIT Solutions
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|