Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error 3061 too few parameters / QueryDef Parameter Problem

Posted on 2009-07-14
11
Medium Priority
?
978 Views
Last Modified: 2013-11-29
Hi all,

First time posting and pretty new at this, so apologies in advance for any stupidity...I'm building a bookings database in MS Access and have created a command button ("Command25") on a form ("subfrmBooking") which is supposed to send a confirmation email to a student who is booked in for an appointment with an attachment ("rptBookingConfirmationEmail").

I have created a query ("qryBookingIDAndStudentEmail") which selects "StudentEmail" from a table ("Student") and BookingID from a table ("Booking") where Booking.BookingID = subfrmBooking.BookingID.  The query seems to work fine; however, when I try to click the command button I am confronted with a pop-up informing me of Error 3061:  Too few parameters.  Expected 1"

I've spent hours trawling previous posts and other sites, and I believe that the problem may relate to my having to define the parameters in the vba editor using QueryDef, but can't seem to get my head around how to apply it to my code, which I've pasted below in the hope that someone might be able to help.

Any advice would be much appreciated!
Private Sub Command25_Click()
On Error GoTo Err_Command25_Click
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lngBookingID As Long
Dim strEmail As String
 
strSQL = "SELECT BookingID,StudentEmail From qryBookingIDAndStudentEmail"
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset(strSQL)
 
rst.MoveFirst
 
    Do While Not rst.EOF
        lngBookingID = rst!BookingID
        strEmail = rst!StudentEmail
        DoCmd.SendObject acSendReport, "rptBookingConfirmationEmail", acFormatHTML, strEmail, , , "Confirmation of Needs Assessment Booking.", "Please find attached details of your pending appointment at CLASS", True
        rst.MoveNext
    Loop
lngpubBookingID = 0
 
MsgBox "Done", vbInformation
 
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
 
Exit_Command25_Click:
    On Error Resume Next
    rst.Close
    Set rst = Nothing
    dbs.Close
    Set dbs = Nothing
    Exit Sub
 
Err_Command25_Click:
    If Err.Number = 2501 Then
        Resume Exit_Command25_Click
    Else
        MsgBox "There was an error sending the email" & vbCrLf & vbCrLf & Err.Number & ": " & vbCrLf & vbCrLf & Error, vbExclamation
        Resume Exit_Command25_Click
End If
End Sub

Open in new window

0
Comment
Question by:mattdc1978
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24851313
this line is possibly causing the error

strSQL = "SELECT BookingID,StudentEmail From qryBookingIDAndStudentEmail"

post the sql view of the query  qryBookingIDAndStudentEmail

you might be using a wrong field name or mispelled field name or query
0
 

Author Comment

by:mattdc1978
ID: 24851479
Thanks for having a look.  The SQL for the query is as follows.

SELECT Student.StudentEmail, Booking.BookingID
FROM Student INNER JOIN (StudentCourse INNER JOIN Booking ON StudentCourse.StudentCourseID = Booking.StudentCourseID) ON Student.StudentID = StudentCourse.StudentID
WHERE (((Booking.BookingID)=[Forms]![frmStudentBooking]![subfrmBooking]![BookingID]));

Not sure if this is relevant, but initially I forgot to add any criteria to qryBookingIDAndStudentEmail.  At that point the command button did everything right (opened Outlook, filled in subject and body text and attached report); with the exception of always obtaining the email address from the first record which is a fairly major thing!
0
 
LVL 77

Expert Comment

by:peter57r
ID: 24851524
Is qryBookingIDAndStudentEmail a parameter query?
If so you can't use it in the way you are trying to and you will need a different approach.
But can you confirm this first?

0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:mattdc1978
ID: 24851573
Yes, it is a parameter query.  Have just this second posted the SQL which includes details.
0
 
LVL 77

Accepted Solution

by:
peter57r earned 1200 total points
ID: 24851631
I think the simplest approach is to take the Where clause out of the saved query and put it into the recordset sql

strSQL = "SELECT BookingID,StudentEmail From qryBookingIDAndStudentEmail  "
strsql = strsql & "wHERE BookingID= " & [Forms]![frmStudentBooking]![subfrmBooking].Form![BookingID]

this assumes bookingid is a number.
0
 

Author Comment

by:mattdc1978
ID: 24851859
Yep, BookingID is a number.

I've put that code into mine and it's telling me there is an error 3075: Syntax error (missing operator) in query expression 'BookingID='

I'm not sure if this is right, but I did also try changing that line to:

strSQL=strSQL & "WHERE BookingID=" & "[Forms]![frmStudentBooking]![subfrmBooking].Form![BookingID]"

When I tried that, it gave me error 3061 - too few parameters - again.
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 800 total points
ID: 24852010
thats right, peter is on the right track
copy and paste this

strSQL = "SELECT BookingID,StudentEmail From qryBookingIDAndStudentEmail"
strSQL=strSQL & " WHERE BookingID=" & [Forms]![frmStudentBooking]![subfrmBooking].Form![BookingID]
0
 
LVL 77

Expert Comment

by:peter57r
ID: 24852548
!peter is on the right track"???
On the right track indeed.
If yours is right, Cap,  then mine is too.

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24852606
i know, i just want the asker to copy and paste the sql string.
pardon me if my post lacks explanation.
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 24854609
Just to offer a different option...
A standard function to open your recordsets to allow for Form expressions as parameters in case they're part of it.
The function fDAOGenericRst in this thread.
0
 

Author Closing Comment

by:mattdc1978
ID: 31603333
Guys - thank you so much for this.  It now seems to work perfectly.  :)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question