Link to home
Start Free TrialLog in
Avatar of kevbb
kevbb

asked on

registration form - code to Search table for matching citeria on form...

I have a registration form in my project (ms access)
I have a table that holds username and password (once registered) called "TblUser"
I have another table that I can enter Usernames into manually to allow them access to register or not (TblAllowed)
Basically, while entering registration data (username, new password etc) once the user clicks on the register button, I would like it to check
1. If the username already exists (TblUser)
2. If they are allowed to register (check if their name is in TblAllowed.)
below is some of the code which Im using, but it only seems to look at the first names in the tables, not all of them.

If Me.TxtUser.Text <> DLookup("AllowedAccess", "TblAllowed", "[AllowedAccess]") Then
MsgBox "Im sorry you are not Authorised to use this database...please see Admin for Access rights", vbOKOnly, "Access Error!!"
ElseIf Me.TxtUser.Text = DLookup("UserName", "TblUser", "[Username]") Then
MsgBox "User already exists, try again!!", vbOKOnly, "User Name Error"

Being fairly new at this, any help and explanations would go a long way.

Kind Rgds / Kevbb.
Avatar of CWS (haripriya)
CWS (haripriya)
Flag of India image

Can you post your DLookup function
Avatar of kevbb
kevbb

ASKER

Im sorry cyberwebservice im a bit confused by your question?

Im using Microsoft Access, and, although Im fairly new at this, I believe the DLookup is a built in function of Microsoft Access, so I cannot post the code.

Rgds / Kevbb.
Please post your query under the Topic MS Access.
SOLUTION
Avatar of omgang
omgang
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Function LookupUser()
Dim rs As DAO.Recordset
Dim rs1 As DAO.Recordset
Dim strSQL As String
Dim strUserName As String
strUserName = Me.TxtUser.Text
rs.OpenRecordset ("Select * from TblUser where UserName = " & strUserName)
If rs.RecordCount > 0 Then
MsgBox "User already exists, try again!!", vbOKOnly, "User Name Error"
End If
rs1.OpenRecordset ("Select * from TblAllowed where AllowedAccess = " & strUserName)
If Not rs1.RecordCount > 0 Then
MsgBox "Im sorry you are not Authorised to use this database...please see Admin for Access rights", vbOKOnly, "Access Error!!"
End If
rs.Close
rs1.Close
Set rs = Nothing
Set rs1 = Nothing

End Function
Later Rock!!!
J
You never really said what you wanted to do If the user can actually register. Should we assume you have already coded that and you know where you want to include the lookups? Let us know.
J


Avatar of kevbb

ASKER

Thanks People...you all helpd me out lot's. I really appreciate the explanations of what the functions are doing.

Cheers / Kevbb.
No probs