Solved

MS Access Log On form

Posted on 2004-08-27
8
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

756 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