Run-time error 3061 when trying to email query results that is linked to a form (1 Viewer)

cykchanaa

New member
Local time
Today, 20:58
Joined
Jul 17, 2015
Messages
5
I am trying to create a form button that will automatically email each row of a query result to myself. At first the VBA code worked fine with a standard query. However when I use it with a query that contains a reference to a combobox form such as "<=[Forms]![Reminder]![Monthsleft].[Value] And >=0" I get the 3061 run-time error and "Too few parameters. Expected 1." I have included the VBA code below.

Private Sub Command9_Click()
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim sToName As String
Dim sSubject As String
Dim sMessageBody As String

Set MyDb = CurrentDb()
Set rsEmail = MyDb.OpenRecordset("Query2", dbOpenDynaset)

With rsEmail
.MoveFirst
Do Until rsEmail.EOF
sToName = "CPPKENC"
sSubject = "Lease Reminder " & .Fields(4) & " in " & .Fields(3) & " will expire on " & .Fields(7)
sMessageBody = "We note that the lease of your Engineering Office in Hyderabad will expire on " & .Fields(7) & " If you intend to renew the lease, terms and conditions will need to be submitted for ECC for approval (regardless of changes or not in lease rates). If the terms have yet to be confirmed, it is important to begin the negotiation process as soon as possible with a target to provide the ECC submission at least two months prior to the commencement date of the renewed lease. To ensure sufficient time for ECC approval before the contract expiry date, please prepare the ECC paper and obtain necessary endorsements. Submission details can be found here. The ECC submission template and PSD Questionnaire could be found from this link. Please clearly presents the terms & rent of current and new lease for easy reference. Please do not hesitate to contact us should you require any assistance or guidance in respect of the lease renewal negotiations. Regards, Shirley"


DoCmd.SendObject acSendNoObject, , , _
sToName, , , sSubject, sMessageBody, False, False

.MoveNext
Loop
End With

Set MyDb = Nothing
Set rsEmail = Nothing
End Sub
 

Ranman256

Well-known member
Local time
Today, 08:58
Joined
Apr 9, 2015
Messages
4,339
Make sure in the query, that
"<=[Forms]![Reminder]![Monthsleft].[Value] And >=0"
is NOT inside the double quotes.
(not sure it this is text from the query or you just posting it)

If no quotes, DO NOT use the property: .VALUE
use: [Forms]![Reminder]![Monthsleft]

it fails,...just use the object...it knows to use the value.

IF it STILL fails, you can put [Forms]![Reminder]![Monthsleft] in the PARAMETER property. You shouldnt have to , (except for crosstabs) but you can.
in a query, on the toolbar, click pararmeters button, add [Forms]![Reminder]![Monthsleft]
 

cykchanaa

New member
Local time
Today, 20:58
Joined
Jul 17, 2015
Messages
5
Make sure in the query, that
"<=[Forms]![Reminder]![Monthsleft].[Value] And >=0"
is NOT inside the double quotes.
(not sure it this is text from the query or you just posting it)

If no quotes, DO NOT use the property: .VALUE
use: [Forms]![Reminder]![Monthsleft]

it fails,...just use the object...it knows to use the value.

IF it STILL fails, you can put [Forms]![Reminder]![Monthsleft] in the PARAMETER property. You shouldnt have to , (except for crosstabs) but you can.
in a query, on the toolbar, click pararmeters button, add [Forms]![Reminder]![Monthsleft]

I tried both methods but am still getting the error.
 

Users who are viewing this thread

Top Bottom