Click here to Skip to main content
15,891,800 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my vba code for access is not working and it is showing some kind of runtime error. please help me out
here is the code
in block is the error line it says that one more required parameters are not given values



VB
Private Sub Command7_Click()
Dim err As Boolean
Dim con1 As ADODB.Connection
Dim recSet1 As ADODB.Recordset
Dim strSQL As String

'check that the user enter something
txtuName.SetFocus
If txtuName.Text = "" Then
    MsgBox "Please enter all required information."
    err = True
End If

'check that the user entered valid data i.e non-numerical
txtuPass.SetFocus
If txtuPass.Text = "" Then
    MsgBox "Enter password"
    err = True
End If

If IsNumeric(txtuPass) Then
    MsgBox "Invalid format"
    txtuPass.SetFocus
    err = True
End If

txtuPass.SetFocus
If Len(txtuPass) > 10 Then
    MsgBox "Please check your password and try again"
    err = True
End If

'run sql query to verify that the user exist
txtuName.SetFocus

If Not err Then
    SQL = "SELECT uName, uPass FROM users WHERE uName=" & txtuName.Text
    Set con1 = CurrentProject.Connection
    Set recSet1 = New ADODB.Recordset
    recSet1.Open SQL, con1

    If recset.RecordCount > 10 Then
        'user does exist in database
        MsgBox "You can access the application"
    Else
        'user does not exist
        MsgBox "Your login details do not match"
    End If    'recordcount


    recset.Close
    con.Close
    Set con = Nothing
    Set recset = Nothing
End If

End Sub
Posted
Updated 5-Mar-11 1:03am
v2
Comments
Maciej Los 6-Mar-11 17:10pm    
Take a look at msdn site:
http://msdn.microsoft.com/en-us/library/ms675544%28v=vs.85%29.aspx

1 solution

OK, i see 2 problems:
1) SQL variable.
SQL = "SELECT uName, uPass FROM users WHERE uName=""" & txtuName.Text & """"

or
SQL = "SELECT uName, uPass FROM users WHERE uName='" & txtuName.Text & "'"

Read more about: writing queries T-SQL (google).

2) As i wrote before recordset.Open method has many parameters. Check CursorType and LockType parameters on http://msdn.microsoft.com/en-us/library/ms675544%28v=vs.85%29.aspx[^] and set it properly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900