Solved Finding Duplicate entry

sbaud2003

Member
Local time
Tomorrow, 03:29
Joined
Apr 5, 2020
Messages
186
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.
 
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.
 
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

Back
Top Bottom