'Too Few Parameters' Error (1 Viewer)

mathboy23

New member
Local time
Today, 23:37
Joined
May 3, 2001
Messages
7
I am creating a log-in form for a database and am running into a 'Too few parameters' error when trying to login. I am using the login form to determine which form should be opened (based on a user's department) and to use the login ID as a parameter in a query. Here is the code I am using on the login form that is producing the error:

Private Sub txtLoginID_Exit(Cancel As Integer)
On Error GoTo Err_txtLoginID_Exit

Dim dbs As Database, rst As Recordset
Dim SQL As String
Dim strLoginID As String

txtLoginID.SetFocus
SQL = "SELECT tblRep.Dept FROM tblRep WHERE tblRep.RACFID= txtLoginID.Text"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(SQL, dbOpenDynaset)

If rst.RecordCount > 0 Then
gblLoginID = txtLoginID.Text
Select Case rst("Dept")
Case "Inbound"
DoCmd.Close
DoCmd.OpenForm "frmPipeline"
Case "CoBrand"
DoCmd.Close
DoCmd.OpenForm "frmPipeline"
Case "Outbound"
DoCmd.Close
DoCmd.OpenForm "frmPipeline"
Case "Retention"
DoCmd.Close
DoCmd.OpenForm "frmPipleine"
Case "Manager"
DoCmd.Close
DoCmd.OpenForm "frmPipeline"
Case "Fulfillment"
DoCmd.Close
DoCmd.OpenForm "frmFulfillment"
End Select
Else
MsgBox "Please re-enter your RACF ID"
End If

rst.Close
Set dbs = Nothing

Exit_txtLoginID_Exit:
Exit Sub

Err_txtLoginID_Exit:
MsgBox Err.Description
Resume Exit_txtLoginID_Exit

End Sub

Any suggestions? Thanks in advance!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:37
Joined
Feb 19, 2002
Messages
43,302
Jet is not able to parse the SQL statement as it is written. Change it to:

SQL = "SELECT tblRep.Dept FROM tblRep WHERE tblRep.RACFID= '" & Me.txtLoginID & "'"

You need to isolate the variable so that VBA can provide the value for txtLoginID and pass it to Jet inside quotes since it is a string value.
 

mathboy23

New member
Local time
Today, 23:37
Joined
May 3, 2001
Messages
7
Thanks Pat,

That has solved the issue. I've had to change the code where I had some other messy stuff, but this is my first try at coding, so figured I'd learn something new.
 

Users who are viewing this thread

Top Bottom