Edit code to use integer instead of text

G

Guest

I found a link via this forum to Prevent dupes

http://www.databasedev.co.uk/duplicates.html

It is just what I need, however, the field used in example is text and my
field is integer.

How can I edit this code to use integet instead of text?

'*********************************
'Code sample courtesy of srfreeman
'*********************************

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

Set rsc = Me.RecordsetClone

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

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

Set rsc = Nothing
End Sub


Thanks tons,
 
R

ruralguy via AccessMonster.com

Simply leave off the quotes!
stLinkCriteria = "[strStudentNumber]=" & SID

I found a link via this forum to Prevent dupes

http://www.databasedev.co.uk/duplicates.html

It is just what I need, however, the field used in example is text and my
field is integer.

How can I edit this code to use integet instead of text?

'*********************************
'Code sample courtesy of srfreeman
'*********************************

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

Set rsc = Me.RecordsetClone

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

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

Set rsc = Nothing
End Sub

Thanks tons,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top