Too few parameters error mess. - need help plz

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good day all,

i'm getting an error mess. (Too Few Parameters. Expected 4.) each time I'm
trying to execute this code. If anyone knows how to fix it it will be great..


Private Sub PrintSN_Click()
On Error GoTo PrintSN_Click_Err
Dim rstTP As DAO.Recordset
Dim FILENAME As String
Dim FILE, SystFic
Dim RecNo, RecCnt As Integer

crlf = Chr(13) + Chr(10)

Crit_1 = "((Part_Number_ID) = " & PartID & ")"
Crit_2 = "((week_number) = " & WeekNo & ")"
Crit_3 = "((Year_number) = " & YearNo & ")"
Crit_4 = "((Seq_number) between Val(" & First & ") And Val(" & Last & "))"

sqlSelect = "SELECT Seq_number, Part_Number_ID, week_number,
Year_number"
sqlFrom = "FROM Bar_Code_Label_Part_number LEFT JOIN
Serial_Numbers_WW_YY_NNNN" & _
"ON Bar_Code_Label_Part_number.ID =
Serial_Numbers_WW_YY_NNNN.Part_number_ID"
sqlWhere ="WHERE(" & Crit_1 & " And " & Crit_2 & " And " & Crit_3 & "
And " &
Crit_4 & ")"
sqlOrder = "ORDER BY Seq_number;"

StrSQL = sqlSelect

If (IsNull(First) Or IsNull(Last)) Then _
MsgBox ("Please select the range of labels to print!"),
vbExclamation: GoTo PrintSN_Click_Exit

FILENAME = week_number & "" & _
Year_number & "" & _
Seq_number & "" & _
First & "_to_" & Last & ".txt"

Close #1
Open FILENAME For Output As #1
Set rstTP = CurrentDb().OpenRecordset(StrSQL)
RecCnt = rstTP.RecordCount <== Seems to
hang here..
While Not rstTP.EOF
With rstTP
Print #1, "PartID " & !Part_Number_ID & crlf & _
"Year " & !Year_number & crlf & _
"Week " & !week_number & crlf & _
"Seq " & !Seq_number
.MoveNext
End With
Wend
 
Marty,

Your strSQL string contains only the sqlSelect part, you have forgotten to
add the From, Where and Sort clauses, so it is not a valid SQL expression.
Try changing:

StrSQL = sqlSelect

To:

StrSQL = sqlSelect & " " & sqlFrom & " " & sqlWhere & " " & sqlOrder

HTH,
Nikos
 
Thanks a lot for the hint! works just fine now

:0)


Nikos Yannacopoulos said:
Marty,

Your strSQL string contains only the sqlSelect part, you have forgotten to
add the From, Where and Sort clauses, so it is not a valid SQL expression.
Try changing:

StrSQL = sqlSelect

To:

StrSQL = sqlSelect & " " & sqlFrom & " " & sqlWhere & " " & sqlOrder

HTH,
Nikos
 
Back
Top