Results 1 to 6 of 6

Thread: Access 2003 Form error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Question 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:
    1. Private Sub cmdFORM25_Click()
    2.  
    3. Dim sSQL As String
    4. Dim stNum As String
    5. stNum = "25"
    6. sSQL = "SELECT * FROM SATETRAINING WHERE Comments = stNum"
    7. [COLOR=Red]Set rs = CurrentDb.OpenRecordset(sSQL)[/COLOR]
    8. Do While Not rs.EOF
    9. Dim stName As String
    10. Dim stSubject As String
    11. Dim stText As String
    12. Dim stEmail As String
    13. stEmail = "[email protected]"
    14. stName = rs!FullName
    15. stSubject = "Form 25 needed for" & stName
    16. stText = "You do not have a Form 25 on File." & Chr$(13) & _
    17. "Please drop off a copy at the Finance Customer Service Desk." & Chr$(13) & _
    18. "If you do not turn in your Form 25 Comm may take away your network privileges."
    19. DoCmd.SendObject , , acFormatTXT, stEmail, , stSubject, stText, -1
    20. rs.MoveNext
    21. Loop
    22.  
    23.  
    24. End Sub

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Access 2003 Form error

    try putting the value of your variable into the SQL, instead of the variable name
    VB Code:
    1. sSQL = "SELECT * FROM SATETRAINING WHERE Comments = " & stNum

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    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:
    1. 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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: Access 2003 Form error

    Quote Originally Posted by si_the_geek
    try putting the value of your variable into the SQL, instead of the variable name
    VB Code:
    1. sSQL = "SELECT * FROM SATETRAINING WHERE Comments = " & stNum
    Now I get:

    Data Type Mismatch in criteria expression

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Long Island, NY.
    Posts
    353

    Re: Access 2003 Form error

    You know what this value never changes, so can't I put

    VB Code:
    1. sSQL = "SELECT * FROM SATETRAINING WHERE Comments = 25 "

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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:
    1. sSQL = "SELECT * FROM SATETRAINING WHERE Comments = '" & stNum & "'"
    2. 'or:
    3. 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
  •  



Click Here to Expand Forum to Full Width