Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error on duplicate prevention code

Status
Not open for further replies.

Chew407

Technical User
Mar 28, 2005
92
CA
I am using the following code to check if the invoice being entered already exists within the db. I get the "compile error: User-defined type not defined" What is the solution to this eorror? Thanks in advance for your help! :)

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

    Set rsc = Me.RecordsetClone

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

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

    Set rsc = Nothing
End Sub
 
You have to reference the Microsoft DAO object library.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Oops, of course! Thank you PHV!

How might I be able to alter this code to look up the value from two fields instead of just one to determine if the current entry would be a duplicate?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top