|
-
Jan 26th, 2006, 09:43 AM
#1
Thread Starter
Hyperactive Member
Access 2003 Form error
I keep getting an error that says "Too few parameters. Expected 1." on the line I colored RED
Any ideas where I went wrong. I did reference the Microsoft Outlook 11.0 Library
VB Code:
Private Sub cmdFORM25_Click()
Dim sSQL As String
Dim stNum As String
stNum = "25"
sSQL = "SELECT * FROM SATETRAINING WHERE Comments = stNum"
[COLOR=Red]Set rs = CurrentDb.OpenRecordset(sSQL)[/COLOR]
Do While Not rs.EOF
Dim stName As String
Dim stSubject As String
Dim stText As String
Dim stEmail As String
stName = rs!FullName
stSubject = "Form 25 needed for" & stName
stText = "You do not have a Form 25 on File." & Chr$(13) & _
"Please drop off a copy at the Finance Customer Service Desk." & Chr$(13) & _
"If you do not turn in your Form 25 Comm may take away your network privileges."
DoCmd.SendObject , , acFormatTXT, stEmail, , stSubject, stText, -1
rs.MoveNext
Loop
End Sub
-
Jan 26th, 2006, 09:55 AM
#2
Re: Access 2003 Form error
try putting the value of your variable into the SQL, instead of the variable name 
VB Code:
sSQL = "SELECT * FROM SATETRAINING WHERE Comments = " & stNum
-
Jan 26th, 2006, 10:16 AM
#3
Frenzied Member
Re: Access 2003 Form error
if stNum is a string, you'd need to enclose it within single quotes. This assumes the Comments field is text.
VB Code:
sSQL = "SELECT * FROM SATETRAINING WHERE Comments = '" & stNum & "'"
Otherwise dim it as an integer. You may also want to pass the value in as a variable to the sub rather than hardcoding it, or get it some other way (InputBox, Form, etc).
Your error could also occur if you haven't declared rs somewhere else at at least module level.
Tengo mas preguntas que contestas
-
Jan 26th, 2006, 10:43 AM
#4
Thread Starter
Hyperactive Member
Re: Access 2003 Form error
 Originally Posted by si_the_geek
try putting the value of your variable into the SQL, instead of the variable name
VB Code:
sSQL = "SELECT * FROM SATETRAINING WHERE Comments = " & stNum
Now I get:
Data Type Mismatch in criteria expression
-
Jan 26th, 2006, 10:44 AM
#5
Thread Starter
Hyperactive Member
Re: Access 2003 Form error
You know what this value never changes, so can't I put
VB Code:
sSQL = "SELECT * FROM SATETRAINING WHERE Comments = 25 "
-
Jan 26th, 2006, 11:37 AM
#6
Re: Access 2003 Form error
"Data Type Mismatch" means that (like in VB) you haven't used the right data type for something, and as salvelinus thought your Comments field appears to be a string, so you must use quotes, ie:
VB Code:
sSQL = "SELECT * FROM SATETRAINING WHERE Comments = '" & stNum & "'"
'or:
sSQL = "SELECT * FROM SATETRAINING WHERE Comments = '25' "
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|