A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Email Mail Merge Code Run Time Error



 
 
Thread Tools Display Modes
  #1  
Old July 10th, 2009, 10:42 PM posted to microsoft.public.access
Confused
external usenet poster
 
Posts: 498
Default Email Mail Merge Code Run Time Error

I have this Function to run on a query called "EmailQuery" . This code opens
my email and populates all of the names in the BCC field. Now when I click
the Cmd button I get a Run-Time Error with the message 'Too Few Parameters.
Expected 1.' The line it highlights in the code below is Set RS =
DBEngine(0)(0).OpenRecordset(sSQL)

I added a subquery to the SQL to filter the form EmailQuery when it opens
to this query, but I didn't do anything to the code below ( not sure if this
is related to the problem).


Private Sub Command14_Click()
DoCmd.SendObject acSendNoObject, , , , , EmailonQ1, "Subject", "Message",
True, False

End Sub

Public Function EmailonQ1()
Dim RS As DAO.Recordset
Dim tmpEM As String
Dim sSQL As String
sSQL = "SELECT emailquery.emailaddress " & _
"FROM emailquery where [send to?] = -1 ;"
Set RS = DBEngine(0)(0).OpenRecordset(sSQL)
RS.MoveFirst
Do While Not RS.EOF
tmpEM = tmpEM & Nz(RS.Fields(0).Value, "") & ";"
RS.MoveNext
Loop
EmailonQ = tmpEM
Set RS = Nothing

End Function

Much appreciate any help resolving...
  #2  
Old July 10th, 2009, 11:02 PM posted to microsoft.public.access
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default Email Mail Merge Code Run Time Error

The error indicates you ave something misspelled in the SQL string. Try and
run that Select query directly and see what happens.

Confused wrote:
I have this Function to run on a query called "EmailQuery" . This code opens
my email and populates all of the names in the BCC field. Now when I click
the Cmd button I get a Run-Time Error with the message 'Too Few Parameters.
Expected 1.' The line it highlights in the code below is Set RS =
DBEngine(0)(0).OpenRecordset(sSQL)

I added a subquery to the SQL to filter the form EmailQuery when it opens
to this query, but I didn't do anything to the code below ( not sure if this
is related to the problem).

Private Sub Command14_Click()
DoCmd.SendObject acSendNoObject, , , , , EmailonQ1, "Subject", "Message",
True, False

End Sub

Public Function EmailonQ1()
Dim RS As DAO.Recordset
Dim tmpEM As String
Dim sSQL As String
sSQL = "SELECT emailquery.emailaddress " & _
"FROM emailquery where [send to?] = -1 ;"
Set RS = DBEngine(0)(0).OpenRecordset(sSQL)
RS.MoveFirst
Do While Not RS.EOF
tmpEM = tmpEM & Nz(RS.Fields(0).Value, "") & ";"
RS.MoveNext
Loop
EmailonQ = tmpEM
Set RS = Nothing

End Function

Much appreciate any help resolving...


--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200907/1

  #3  
Old July 10th, 2009, 11:26 PM posted to microsoft.public.access
Confused
external usenet poster
 
Posts: 498
Default Email Mail Merge Code Run Time Error

The Select Query works fine. It asks for a parameter value, which is what I
built. The EmailQuery opens fine and displays all of the records or the
records as a result of the parameter classification. The code was working
fine and I didn't change anything on the function. It's just now the only
thing different is there is a parameter (subquery) on the SQL Statement.
I'm not sure if this is related to the problem, because I haven't ran the
code in several days.

"ruralguy via AccessMonster.com" wrote:

The error indicates you ave something misspelled in the SQL string. Try and
run that Select query directly and see what happens.

Confused wrote:
I have this Function to run on a query called "EmailQuery" . This code opens
my email and populates all of the names in the BCC field. Now when I click
the Cmd button I get a Run-Time Error with the message 'Too Few Parameters.
Expected 1.' The line it highlights in the code below is Set RS =
DBEngine(0)(0).OpenRecordset(sSQL)

I added a subquery to the SQL to filter the form EmailQuery when it opens
to this query, but I didn't do anything to the code below ( not sure if this
is related to the problem).

Private Sub Command14_Click()
DoCmd.SendObject acSendNoObject, , , , , EmailonQ1, "Subject", "Message",
True, False

End Sub

Public Function EmailonQ1()
Dim RS As DAO.Recordset
Dim tmpEM As String
Dim sSQL As String
sSQL = "SELECT emailquery.emailaddress " & _
"FROM emailquery where [send to?] = -1 ;"
Set RS = DBEngine(0)(0).OpenRecordset(sSQL)
RS.MoveFirst
Do While Not RS.EOF
tmpEM = tmpEM & Nz(RS.Fields(0).Value, "") & ";"
RS.MoveNext
Loop
EmailonQ = tmpEM
Set RS = Nothing

End Function

Much appreciate any help resolving...


--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200907/1


  #4  
Old July 10th, 2009, 11:34 PM posted to microsoft.public.access
Confused
external usenet poster
 
Posts: 498
Default Email Mail Merge Code Run Time Error

I removed the parameter (the where statement on the SQL string) and now the
code runs fine. It opens my email and populates all of the names. Just need
to know if I can make it still work with the subquery? Or another way to
accomplish the same thing? Just trying to populate names automatically in a
BCC message in email. Thanks!

"Confused" wrote:

The Select Query works fine. It asks for a parameter value, which is what I
built. The EmailQuery opens fine and displays all of the records or the
records as a result of the parameter classification. The code was working
fine and I didn't change anything on the function. It's just now the only
thing different is there is a parameter (subquery) on the SQL Statement.
I'm not sure if this is related to the problem, because I haven't ran the
code in several days.

"ruralguy via AccessMonster.com" wrote:

The error indicates you ave something misspelled in the SQL string. Try and
run that Select query directly and see what happens.

Confused wrote:
I have this Function to run on a query called "EmailQuery" . This code opens
my email and populates all of the names in the BCC field. Now when I click
the Cmd button I get a Run-Time Error with the message 'Too Few Parameters.
Expected 1.' The line it highlights in the code below is Set RS =
DBEngine(0)(0).OpenRecordset(sSQL)

I added a subquery to the SQL to filter the form EmailQuery when it opens
to this query, but I didn't do anything to the code below ( not sure if this
is related to the problem).

Private Sub Command14_Click()
DoCmd.SendObject acSendNoObject, , , , , EmailonQ1, "Subject", "Message",
True, False

End Sub

Public Function EmailonQ1()
Dim RS As DAO.Recordset
Dim tmpEM As String
Dim sSQL As String
sSQL = "SELECT emailquery.emailaddress " & _
"FROM emailquery where [send to?] = -1 ;"
Set RS = DBEngine(0)(0).OpenRecordset(sSQL)
RS.MoveFirst
Do While Not RS.EOF
tmpEM = tmpEM & Nz(RS.Fields(0).Value, "") & ";"
RS.MoveNext
Loop
EmailonQ = tmpEM
Set RS = Nothing

End Function

Much appreciate any help resolving...


--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200907/1


  #5  
Old July 10th, 2009, 11:41 PM posted to microsoft.public.access
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default Email Mail Merge Code Run Time Error

What is the SubQuery?

Confused wrote:
I removed the parameter (the where statement on the SQL string) and now the
code runs fine. It opens my email and populates all of the names. Just need
to know if I can make it still work with the subquery? Or another way to
accomplish the same thing? Just trying to populate names automatically in a
BCC message in email. Thanks!

The Select Query works fine. It asks for a parameter value, which is what I
built. The EmailQuery opens fine and displays all of the records or the

[quoted text clipped - 41 lines]

Much appreciate any help resolving...


--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200907/1

  #6  
Old July 11th, 2009, 01:09 AM posted to microsoft.public.access
Confused
external usenet poster
 
Posts: 498
Default Email Mail Merge Code Run Time Error

When I remove the Where clause on the below SQL, the function runs fine.
More details if needed -The where clause restricts the form EmailQuery to the
value in CboEmployees, which is based on the query of the same name-
EmailQuery. The form opens and I hit the command button to send an email to
those restricted records and I get the error...

SELECT CLECS2.[CLEC Name], Contacts.[First Name], Contacts.[Last Name],
Contacts.EmailAddress, Contacts.[Send to?], Contacts.CLECID,
Contacts.[Contact ID]
FROM CLECS2 RIGHT JOIN Contacts ON CLECS2.CLECID = Contacts.CLECID
WHERE (((Contacts.EmailAddress) Is Not Null) AND ((CLECS2.CLECID) In (SELECT
CLECID FROM tblEmployeeAssignments WHERE tblEmployeeAssignments.EmployeeID =
[Forms]![CLECS2wContactsSubform]![cboEmployees]
Or[Forms]![CLECS2wContactsSubform]![cboEmployees] is null )));


"ruralguy via AccessMonster.com" wrote:

What is the SubQuery?

Confused wrote:
I removed the parameter (the where statement on the SQL string) and now the
code runs fine. It opens my email and populates all of the names. Just need
to know if I can make it still work with the subquery? Or another way to
accomplish the same thing? Just trying to populate names automatically in a
BCC message in email. Thanks!

The Select Query works fine. It asks for a parameter value, which is what I
built. The EmailQuery opens fine and displays all of the records or the

[quoted text clipped - 41 lines]

Much appreciate any help resolving...


--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200907/1


  #7  
Old July 11th, 2009, 01:29 AM posted to microsoft.public.access
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default Email Mail Merge Code Run Time Error

Did you Copy and Paste the SQL or type it again because the last OR does not
have a space after it.

Confused wrote:
When I remove the Where clause on the below SQL, the function runs fine.
More details if needed -The where clause restricts the form EmailQuery to the
value in CboEmployees, which is based on the query of the same name-
EmailQuery. The form opens and I hit the command button to send an email to
those restricted records and I get the error...

SELECT CLECS2.[CLEC Name], Contacts.[First Name], Contacts.[Last Name],
Contacts.EmailAddress, Contacts.[Send to?], Contacts.CLECID,
Contacts.[Contact ID]
FROM CLECS2 RIGHT JOIN Contacts ON CLECS2.CLECID = Contacts.CLECID
WHERE (((Contacts.EmailAddress) Is Not Null) AND ((CLECS2.CLECID) In (SELECT
CLECID FROM tblEmployeeAssignments WHERE tblEmployeeAssignments.EmployeeID =
[Forms]![CLECS2wContactsSubform]![cboEmployees]
Or[Forms]![CLECS2wContactsSubform]![cboEmployees] is null )));

What is the SubQuery?

[quoted text clipped - 9 lines]

Much appreciate any help resolving...


--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200907/1

  #8  
Old July 11th, 2009, 01:53 AM posted to microsoft.public.access
Confused
external usenet poster
 
Posts: 498
Default Email Mail Merge Code Run Time Error

I copied and pasted. I added the space and got the same results (really
hoping that would have fixed it). Maybe something in the function needs to
be changed? The where clause for some reason interfereing with the function
code?

"ruralguy via AccessMonster.com" wrote:

Did you Copy and Paste the SQL or type it again because the last OR does not
have a space after it.

Confused wrote:
When I remove the Where clause on the below SQL, the function runs fine.
More details if needed -The where clause restricts the form EmailQuery to the
value in CboEmployees, which is based on the query of the same name-
EmailQuery. The form opens and I hit the command button to send an email to
those restricted records and I get the error...

SELECT CLECS2.[CLEC Name], Contacts.[First Name], Contacts.[Last Name],
Contacts.EmailAddress, Contacts.[Send to?], Contacts.CLECID,
Contacts.[Contact ID]
FROM CLECS2 RIGHT JOIN Contacts ON CLECS2.CLECID = Contacts.CLECID
WHERE (((Contacts.EmailAddress) Is Not Null) AND ((CLECS2.CLECID) In (SELECT
CLECID FROM tblEmployeeAssignments WHERE tblEmployeeAssignments.EmployeeID =
[Forms]![CLECS2wContactsSubform]![cboEmployees]
Or[Forms]![CLECS2wContactsSubform]![cboEmployees] is null )));

What is the SubQuery?

[quoted text clipped - 9 lines]

Much appreciate any help resolving...


--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200907/1


  #9  
Old July 11th, 2009, 02:09 AM posted to microsoft.public.access
Confused
external usenet poster
 
Posts: 498
Default Email Mail Merge Code Run Time Error

This was in the help section. This sort of looks like it's expecting the
parameter again...Maybe some way to make the command button not look at the
subquery again but just run the code....Grasping at straws.

Too few parameters. Expected number. (Error 3061)
This parameter query requires the specified number of parameters, which you
did not supply. Provide the expected number of parameters, and run the query
again.

In some cases, this message is generated when unknown field names or
expressions are interpreted as query parameters. Be sure to enclose field
names containing spaces or punctuation with square brackets [ ].


"Confused" wrote:

I copied and pasted. I added the space and got the same results (really
hoping that would have fixed it). Maybe something in the function needs to
be changed? The where clause for some reason interfereing with the function
code?

"ruralguy via AccessMonster.com" wrote:

Did you Copy and Paste the SQL or type it again because the last OR does not
have a space after it.

Confused wrote:
When I remove the Where clause on the below SQL, the function runs fine.
More details if needed -The where clause restricts the form EmailQuery to the
value in CboEmployees, which is based on the query of the same name-
EmailQuery. The form opens and I hit the command button to send an email to
those restricted records and I get the error...

SELECT CLECS2.[CLEC Name], Contacts.[First Name], Contacts.[Last Name],
Contacts.EmailAddress, Contacts.[Send to?], Contacts.CLECID,
Contacts.[Contact ID]
FROM CLECS2 RIGHT JOIN Contacts ON CLECS2.CLECID = Contacts.CLECID
WHERE (((Contacts.EmailAddress) Is Not Null) AND ((CLECS2.CLECID) In (SELECT
CLECID FROM tblEmployeeAssignments WHERE tblEmployeeAssignments.EmployeeID =
[Forms]![CLECS2wContactsSubform]![cboEmployees]
Or[Forms]![CLECS2wContactsSubform]![cboEmployees] is null )));

What is the SubQuery?

[quoted text clipped - 9 lines]

Much appreciate any help resolving...


--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200907/1


  #10  
Old July 11th, 2009, 03:13 AM posted to microsoft.public.access
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default Email Mail Merge Code Run Time Error

It would at least try the following line:
OR IsNull([Forms]![CLECS2wContactsSubform]![cboEmployees])

I know you can use IS NULL on a FIELD in a query but maybe not a CONTROL on a
form.

Confused wrote:
This was in the help section. This sort of looks like it's expecting the
parameter again...Maybe some way to make the command button not look at the
subquery again but just run the code....Grasping at straws.

Too few parameters. Expected number. (Error 3061)
This parameter query requires the specified number of parameters, which you
did not supply. Provide the expected number of parameters, and run the query
again.

In some cases, this message is generated when unknown field names or
expressions are interpreted as query parameters. Be sure to enclose field
names containing spaces or punctuation with square brackets [ ].

I copied and pasted. I added the space and got the same results (really
hoping that would have fixed it). Maybe something in the function needs to

[quoted text clipped - 24 lines]

Much appreciate any help resolving...


--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200907/1

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:14 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.