Check if the data already exist

  • Thread starter Thread starter thekidd
  • Start date Start date
T

thekidd

Guest
Hi,

I put a Dlookup function to compare the new entry in a form and the code is like this:

If (Not IsNull(DLookup("[empno]", "Attnd_tbl" , "[empno]=[empnotxt]")))then
MsgBox "This Employee Already Exists"
cancel = true
Me!empnotxt.undo
end if
end sub

this works for comparing one field only, since I want to check if the employee is already entered on a certain date, how do I put two fields in this function to be looked up if for example "[empno]and[date]","Attnd_tbl","[empno]and[date]=[empnotxt]and[datetxt]"
 
Why not just add the date to the criteria portion of the DLookup, if it returns one, you have a match. Actually I think I would use DCOUNT instead, it would return a zero or > zero which is easier to check. You do not appear to actually need the values.
 
fofa,

Sorry I forgot to mentioned that Im not an advanced Progammer in Access so I really am not familiar with the right codes to write, Ive tried adding the date to the code but it doesnt work probably becuase ive written the code wrong so can you please show how the code should be written including the date that youve mentioned.

Thanks,
 
Kidd,

Code:
If (DCount("[empno]", _
           "Attnd_tbl" , _
           "[empno] = " & Me.empnotxt & "' And " & _
           "[SomeDate] = #" & Me.txtSomeDate & "#")) > 0 Then
   MsgBox "This Employee Already Exists"
   Cancel = True
   Me!empnotxt.undo
End If

Wayne
 

Users who are viewing this thread

Back
Top Bottom