Solved

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

Posted on 2006-06-14
10
205 Views
Last Modified: 2010-04-07
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.
0
Comment
Question by:kevbb
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 16909876
Can you post your DLookup function
0
 

Author Comment

by:kevbb
ID: 16917030
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.
0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 16919779
Please post your query under the Topic MS Access.
0
 
LVL 28

Assisted Solution

by:omgang
omgang earned 50 total points
ID: 16923804


A couple of things:  the DLookup function will return Null if not successful so you have to anticipate this.

Dim varLookup As Variant
 
varLookup = DLookup(.....)
If Is Null varLookup Then
etc.


The DLookup function returns the value of a field in the domain when another (the lookup) field matches some criteria
DLookup("AllowedAccess", "TblAllowed", "[AllowedAccess]") says
return the value of field [AllowedAccess] in domain [TblAllowed] where [AllowedAccess]  ????????????????

I think what you want is
DLookup("AllowedAccess", "TblAllowed", "AllowedAccess = '" & Me.TxtUser & "'")
this will return the value of field AllowedAccess IF it equals the value of field TxtUser on the current form
it will return Null otherwise
If IsNull(DLookup("AllowedAccess", "TblAllowed", "AllowedAccess = '" & Me.TxtUser & "'")) Then
   'your message here
End If

Get the idea?
OM Gang
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 50 total points
ID: 16923819
dlookup returns null if no match found

Do u want to see if current user logged in has access?

1. If they exist in tblUser

assuming Me.txtUser is what they entere

If IsNull(DLOOKUP("UserName","TblUser","UserName = '" & Me.TxtUser & "'")) = True then
    msgbox "user does not exist"
    exit sub
end if


Im assuming accessallowed is a yes/no field?
TblAllowed must have the username or userid stored
Assuming its username

Dim bAccessAllowed as Boolean

bAccessAllowed = NZ(DLOOKUP("AllowedAccess","TblAllowed","UserName = '" & Me.TxtUser & "'"),0)
if bAccessAllowed = False then
    MsgBox "Im sorry you are not Authorised to use this database...please see Admin for Access rights", vbOKOnly, "Access
    exit sub
end if




Hope u get the idea now of using DLOOKUP

This is my last post of the day, I have to leave.
Hopefully Ive given u enough to get you going, else someone else may help
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 34

Expert Comment

by:jefftwilley
ID: 16923862
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
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 16923867
Later Rock!!!
J
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 16923915
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


0
 

Author Comment

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

Cheers / Kevbb.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16931909
No probs
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now