Solved

MS Access Log On form

Posted on 2004-08-27
8
264 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 119

Expert Comment

by:Rey Obrero
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
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 11912813
what is the field type for UserName and Password?
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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 119

Expert Comment

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

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Contents of subform based upon combobox value 3 26
Before insert Image (OLE) resize image 11 42
Sub Reports 8 22
Two list boxes - best structure 3 31
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

920 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

12 Experts available now in Live!

Get 1:1 Help Now