Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone look at this code please

Status
Not open for further replies.

tinatt

Programmer
Jun 18, 2001
15
CA
Hi,

I'm trying to set up my database so that when the user logs into my database if their user name and password is in my table it will then open up a certain form; however, if their user name and password is not in my table it will then open up another form. My code doesn't seem to be working and gives me the error message "Too few parameters. Expected 2". I have no idea what is wrong with my code though. Can someone please have a look at it and give me some suggestions why this is not working. Note, some things have been commented out in my code because I've been trying to troubleshoot the problem. I think the problem might have something to do with my SELECT statement though.

Thanks,
Tina.



Private Sub Command5_Click()

On Error GoTo Err_Command5_Click

Dim db As Database
Dim rs As Recordset

Set db = CurrentDb
Me.txtUserName.SetFocus

'MsgBox txtUserName
'MsgBox txtPassword

Set rs = db.OpenRecordset("SELECT tblUser.User, tblUser.Password FROM tblUser WHERE User = Me.txtUserName AND Password = Me.txtPassword")

'MsgBox "It did the lookup"

If rs.RecordCount <> 1 Then
DoCmd.OpenForm &quot;frmMain_Menu2&quot;, acNormal
'MsgBox &quot;There was a match&quot;
Else
DoCmd.OpenForm &quot;frmMain_Menu1&quot;, acNormal
'MsgBox &quot;There was NOT a match&quot;

End If

Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
End Sub
 
The problem is in the OpenRecordset statement. Change it as follows so the values of your text boxes are passed to the query.

Set rs = db.OpenRecordset(&quot;SELECT tblUser.User, tblUser.Password FROM tblUser WHERE User = '&quot; & Me.txtUserName & &quot;' AND Password = '&quot; & Me.txtPassword & &quot;'&quot;)
Terry

&quot;I'm not dumb. I just have a command of thoroughly useless information.&quot; - Calvin, of Calvin and Hobbes
 
Why not use a DCount instead of the opening of a recordset? It would accomplish the same thing and is a little less complicated..

[tt]
If DCount(&quot;*&quot;,&quot;tblUser&quot;,&quot;[User]=[txtUserName] And [Password]=[txtPassword]&quot;) Then
DoCmd.OpenForm &quot;frmMain_Menu2&quot;, acNormal
Else
DoCmd.OpenForm &quot;frmMain_Menu1&quot;, acNormal
End If
[/tt] Joe Miller
joe.miller@flotech.net
 
Thanks so much for your help guys. You two have both saved me several times.

One more question though, after the user inputs their login information how do I close the form. What's happening now is that the form stays on the screen on top of my Main Menu form. I've never seen this happen before. What should I do?

Thanks ,
Tina
 
IN the after_update event of BOTH text boxes, add a call to a routine (&quot;basValidate&quot;?). In that routine, check that BOTH text boxes are NOT empty. If this is &quot;true&quot; close the form.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top