Solved Finding Duplicate entry (1 Viewer)

sbaud2003

Member
Local time
Today, 12:27
Joined
Apr 5, 2020
Messages
178
Hi ! All
I am having a small registration form where user need to enter name, User ID password and an account number of the Department. I have crated a combo box fetching all the Account No from the data table member, and it was running well.. and it gives error message when already register ID is being chosen. the code is below:


If Me.COMROLE.value = DLookup("[Member_ID]", "[TblUsers]", "[Member_ID] = Forms![Register Form USER1]!COMROLE") Then
MsgBox "This Member with ID:" & DLookup("[Member_ID]", "[TblUsers]", "[Member_ID] = Forms![Register Form USER1]!COMROLE") & "has alreday been Registered, " _
& vbCr & vbCr & "Please Check and enter the correct Member ID", vbOKOnly + vbCritical, "Central Library"

Me.TXTNAME.value = ""
Me.TXTID.value = ""
Me.TXTPASSWORD.value = ""
Me.TXTCNF.value = ""
Me.COMROLE.value = ""
Me.TXTNAME.SetFocus
Exit Sub

End If

Now I want the user to Type the account no in the Text Box and I have converted the Combo Box to Text box, but it is not functioning.
Can any one help me out this.
 

Ranman256

Well-known member
Local time
Today, 02:57
Joined
Apr 9, 2015
Messages
4,337
Do not put form obj paths in quotes in vb...
This assumes the ID is string,
If It is Numeric,you must not use quotes:

If Me.COMROLE.value = DLookup("[Member_ID]", "[TblUsers]", "[Member_ID] = '" & Forms![Register Form USER1]!COMROLE & "'") Then

If this is a query ,DONT use Dlookup.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:57
Joined
Feb 19, 2002
Messages
43,263
Just FYI, "" and Null are different values. "" is only valid in text fields so be careful when you write code like this. Personally, I ALWAYS set AllowZeroLengthString to No because in a field I want to make required, I don't want "" to be a valid value and it will be if you allow ZLS in text fields. To clear all the valued on a form, use just one line of code:
Me.undo
To clear several controls but not all, use:
Me.fld1 = Null
Me.fld2 = Null
rather than ""

Also, there is no reason to use a dLookup() in your error message since you are showing the value you have entered in the form field.
 

Users who are viewing this thread

Top Bottom