Solved

MS Access Log On form

Posted on 2004-08-27
8
273 Views
Last Modified: 2012-06-27
I am using a table named "Users" to store authorized users of the database.  It has two fields named "UserName" and "UserPassword".  I have constructed a simple LogOn form with two text fields named "MyUserName" and "MyPassword".  The LogOn form also has an "OK" button and a "Cancel" button.  I am using the following  code in conjunction with the OnClick function for the "OK" button and I am getting a syntax error in the FROM clause.  Please assist.

Dim rs As Recordset
Set rs = CurrentDb().OpenRecordset("SELECT Users.* FROM Users" & "WHERE(((Users.UserName)=""&Me.MyUserName&"") AND ((Users.UserPassword)=""&Me.MyPassword&"")));")
If rs.Recordset = 0 Then
Beep
MsgBox "Invalid User Name or Password"
RS.Close
Exit Sub
Else
 Open Main switchboard
End If
rs.Close
0
Comment
Question by:terjr
8 Comments
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 50 total points
ID: 11912104
Try this instead:

Set rs = CurrentDb.OpenRecordset ("SELECT Users.* FROM Users WHERE (Users.UserName='" & Me.MyUserName &"' AND Users.UserPassword='" & Me.MyPassword & "')")

Note also that "Users" is a reserved word in Access ... consider adopting a nameing convention, as the use of reserved words can lead to frustration and unexpected behaviour. Google on "nameing convention" for further reading.

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 11912392
good morning Scott,
Actually it is {USER} not {USERS} is the reserved word for access and jet 4.

rey;-)
0
 

Author Comment

by:terjr
ID: 11912494
I changed to the code above and now I get a "type mismatch" error.
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 11912813
what is the field type for UserName and Password?
0
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 75 total points
ID: 11912832
USERS and USER are both reserved words. User is an object of the Users collection.

I suspect the type mismatch comes this:
Dim rs As Recordset

Add a reference to DAO 3.5 (Tools->References, check Microsoft DAO 3.5) and change the line to:
Dim rs As DAO.Recordset
0
 

Author Comment

by:terjr
ID: 11912838
both are text fields
0
 

Author Comment

by:terjr
ID: 11913221
The Reference is grayed out
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 11913273
Click the square button to reset the codes or stop. then tools>references
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

785 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