Solved check if value already exists (1 Viewer)

eshai

Registered User.
Local time
Today, 02:57
Joined
Jul 14, 2015
Messages
193
hi
i have a form for insert students datiles
on the form is failed name "studentid"(text failed) that have index
what i need is when typing a new "id" the code well search if the "id" is already exists

my code

Code:
If IsNull(DLookup("[studentid]", "students", Me.studentid <> 0)) Then
     msgbox = "No Record Found"
Else
   msgbox ="my msg" 
End If
 

isladogs

MVP / VIP
Local time
Today, 00:57
Joined
Jan 14, 2017
Messages
18,209
Replace the first line with one of the following:

Code:
If Nz(DLookup("studentid", "students"),"") ="" Then
OR use
If DCount("studentid", "students") = 0 Then

EDIT: Oops. Right idea but wrongly executed! Use the solution in post #3 or #4 instead!
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 00:57
Joined
Feb 19, 2013
Messages
16,607
try criteria of

"[studentid]=" & Me.studentid

or as colin says, use dcount

Code:
if DCount("*", "students","[studentid]=" &  Me.studentid)=0 then
  'no record found
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:57
Joined
May 7, 2009
Messages
19,231
if studentID is String:

if DCount("*", "students","[studentid]='" & Me.studentid & "'") =0 then
'no record found
else
'your message
end if
 

eshai

Registered User.
Local time
Today, 02:57
Joined
Jul 14, 2015
Messages
193
if studentID is String:

if DCount("*", "students","[studentid]='" & Me.studentid & "'") =0 then
'no record found
else
'your message
end if
work great
thank you
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:57
Joined
May 7, 2009
Messages
19,231
you're welcome :)
 

Users who are viewing this thread

Top Bottom