Two few Parameters Expected 1 Error

AJferlok

New member
Local time
Tomorrow, 06:04
Joined
Mar 8, 2009
Messages
2
Hey Everyone

I am writing an electronic diary appliacation of which the backend is done is sql and the front end is acces. I have created a form for users to login so they are able to keep their diaries private. However on the click event of the logon button i keep getting the error "Two few Parameters Expected 1 Error"

Here is the code:
Code:
Private Sub cmdLogonLogon_Click()

On Error GoTo Err_cmdLogonLogon_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    
    Dim sql As String
    
    Dim username As String
    Dim pass As String
    Dim getPassword As String
    
    Me.txtUsername.SetFocus
    getUsername = Me.txtUsername.Text
    Me.txtPassword.SetFocus
    password = Me.txtPassword.Text
    
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim strSQL As String
    
    Me.txtUsername.SetFocus
    strSQL = "SELECT Password FROM dbo_tblUsers WHERE Username = "   &  Me.txtUsername & ";"
    
    Set dbs = CurrentDb()
    Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)
    
    If rst.RecordCount = 0 Then
    MsgBox "No Data Available"
    Exit Sub
    End If
    rst.MoveLast
    rst.MoveFirst
    
    getPass = rst![password]
    
    If password = getPassword Then
    
    rst.Close
    
    stDocName = "frmUser_Control_Pannel"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    Else
    
    MsgBox ("Error: Username or password  is incorrect.")
    
    Exit Sub
    End If
Exit_cmdLogonLogon_Click:
    Exit Sub
Err_cmdLogonLogon_Click:
    MsgBox Err.Description
    Resume Exit_cmdLogonLogon_Click
    
End Sub

The code crashes here:
Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)

Any help would be great thanks
 
Specifically, you need to delimit the literal string representing your userid in the SQL statement.

But ... I have some more comments on your code:

- The .Text property is not really used as you are using it. To retreive a value that is shown in a text box, I would suggest the use of .Value. Which is the default property of controls and thus does not need to be explicitly specified. The .Text is useful when the user has not committed the value of the text box, so you can see what the user is typing (per se), but as soon as the control looses focus, the .Text property is written to the .Value property.

- Do you have the Option Explicit compiler directive set in your Module? .. if not, you should! It will help you keep your variables straight. You have a many unused similarly named variables, and a variable or two that don't seem to be declared (which defaults them to Variants) ... ie: pass and password.

Here is my suggestion to try ... look specifically how I delimited the value that comes from Me.txtUsername when building the SQL statement. {due take note though, this is AIR CODE, so no debugger assistance!}
Code:
Private Sub cmdLogonLogon_Click()
    
    Dim strSQL As String
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    
    strSQL = "SELECT Password FROM dbo_tblUsers WHERE Username = '" & Me.txtUsername & "';"
    
    Set dbs = CurrentDb()
    Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)
    
    If rst.EOF = True Then
        MsgBox "Error: Username or password  is incorrect."
    Else
        If rst![Password] = Me.txtPassword Then
            DoCmd.OpenForm "frmUser_Control_Pannel"
        Else
            MsgBox "Error: Username or password  is incorrect."
        End If
    End If
    
    rst.Close
    
End Sub

Hope that helps!
 
Hey

Yup that works, im more fammilliar with vb.net so chances are i got confused with how a textbox works in access to how it does in vb.net

ty for all the help
Shows you how much i have to learn still.. :)
 
>> Yup that works <<

Cool! ... extremely glad to here it!

>> how much i have to learn still.. <<

We all have a lot to learn! ... we just need to be open to learn it! ... I certainly do not know vb.net! (yet) ... :) ..

...

Good luck with your project!
 

Users who are viewing this thread

Back
Top Bottom