Avoiding Duplicate Entries

Rupelo

New member
Local time
Yesterday, 20:41
Joined
Nov 21, 2006
Messages
8
Hey guys! How are things?
Well I am having a little problem with this code for duplicate entries
What it supposed to do is when a permit no that is already in the database is entered, it will display a message saying so and then take you to that record itself
Here is how my code looks
However I keep getting an error saying there is a data type mismatch

permitno is a long integer
Also it is in the before update event procedure


Any help would be much appreciated



Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset

Set rsc = Me.RecordsetClone

SID = Me.permitno.Value
stLinkCriteria = "[permitno]=" & "'" & SID & "'"

'Check PERSON table for duplicate Permit Ids
If DCount("permitno", "Person", stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Permit Number " _
& SID & " has already been entered." _
& vbCr & vbCr & "You will now been taken to the record.", vbInformation _
, "Duplicate Information"
'Go to record of original Permit Number
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If

Thanx
RUPELO
 
If permit number is actually a number, get rid of the quotes
Code:
stLinkCriteria = "[permitno]=" & "'" & SID & "'"
Code:
stLinkCriteria = "[permitno]=" & SID
 
Bob's correct as to your problem. Having said that, you should know that it's always better to only use a numerical datatype, such as long integer, if you're actually using the number as a number, i.e. if you're going to do math with it. Otherwise, number not for used for math should actually be of a text datatype.
 
DAmn it I feel like an idiot
Thanx for the hand guys
 
Run-time error

I have put the same code in my database - obiously changing the filed names.
When I test the database by entering in a number I know has already been enetrewd, it correctly tells me that the number has already entered. It does not take me to that record. Just typing this out, I think I realise why it could not be working. Could it be the fact that the form used for enterting the data is a data only form?

The error message iget is Run-time error 3021 No current record.

If the data only form is the problem, how do I bring up the record?
 

Users who are viewing this thread

Back
Top Bottom