Run Time Error 3061

G

Guest

I am trying to use a query's results (a username) to look up the full name of
the individual from the GAL. When i hardcode the username in (ex. below
AB30C), the function will resolve and return the correct username. However,
when i try to run the openrecordset command, i get the runtime 3061 error
stating "too few parameters. Expected 1".

I tried putting my query code directly in instead of the name, but i still
get the same error.

Any help is greatly appreciated.

The code i am running is below:

Function sbSendMessage(userAlias As String)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim objAlias As String
Dim data As DAO.Database
Dim names As DAO.Recordset

Set data = CurrentDb
Set names = data.OpenRecordset("QuerybyMailbox", dbOpenSnapshot)
'Debug.Print names.Updatable

Set objOutlook = CreateObject("Outlook.Application")

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("AB30C")
objOutlookRecip.Type = olTo

objAlias = objOutlookRecip.Resolve
userAlias = objOutlookRecip
End With
End Function
 
G

Guest

Function sbSendMessage(userAlias As String)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
'Bad naming convention. obj should be for Objects, str should be for String
Dim objAlias As String
Dim data As DAO.Database
Dim names As DAO.Recordset
Dim qdf As QueryDef

Set data = CurrentDb
Set qdf = data.QueryDefs("QuerybyMailboxr")
qdf.Parameters(0) = userAlias 'Or whatever variable has the parameter value
Set names = qdf.OpenRecordset(dbOpenSnapshot)
'Debug.Print names.Updatable

Set objOutlook = CreateObject("Outlook.Application")

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("AB30C")
objOutlookRecip.Type = olTo

objAlias = objOutlookRecip.Resolve
userAlias = objOutlookRecip
End With
End Function
 
G

Guest

Thanks for the quick response.
The code you sent me runs with no errors.
but i have one more question. The output of the query gives a username ,
how do i put that in this code to add the query output as a recipient?

With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("Query output")
objOutlookRecip.Type = olTo
 
G

Guest

Sorry, i'll try to make it clearer.
Here is my query SQL code.

SELECT servicemom_alerts.Body, LTrim(Mid(Left([Body],InStr([Body],"logged on
to")-2),InStr([Body],"User ENTN\")+12)) AS Expr1,
LTrim(Mid(Left([Body],InStr([Body],"logged on to")-2),InStr([Body],"User
ENTERPRISE\")+16)) AS Expr2,
IIf(Len([Expr1])>5,[Expr2],[Expr1]) AS Expr3
FROM servicemom_alerts
WHERE (((servicemom_alerts.Body) Like "*" & [Enter Name] & "*"))
ORDER BY LTrim(Mid(Left([Body],InStr([Body],"logged on
to")-2),InStr([Body],"User ENTN\")+12)),
LTrim(Mid(Left([Body],InStr([Body],"logged on to")-2),InStr([Body],"User
ENTERPRISE\")+16));

Pretty much i have the query search through the body of an email for the
string between either "User ENTERPRISE\" or "User ENTN\" and the string
"logged on to"
The output of the qry will be a username of format AA##A (ex. AB30C)

What i was trying to do with the code is to resolve that username into the
full name of the user by accessing the GAL. As i said below, when i hardcode
a username into the code (Set objOutlookRecip = .Recipients.Add("AB30C")), i
get the correct resolved full name as the function return value.

What i am trying to do is get it so that the query output will populate the
..Recipients.Add("aaaaa") field and resolve each username output of the query
into the full name.

I hope i explained it enough, please let me know if you need more.

Thanks!
 
G

Guest

I don't think I am the right person to help with this. I will admit to
having almost no experience interfacing with Outlook. You might start a new
post with this question so others will read it.
Good Luck

bgcpen said:
Sorry, i'll try to make it clearer.
Here is my query SQL code.

SELECT servicemom_alerts.Body, LTrim(Mid(Left([Body],InStr([Body],"logged on
to")-2),InStr([Body],"User ENTN\")+12)) AS Expr1,
LTrim(Mid(Left([Body],InStr([Body],"logged on to")-2),InStr([Body],"User
ENTERPRISE\")+16)) AS Expr2,
IIf(Len([Expr1])>5,[Expr2],[Expr1]) AS Expr3
FROM servicemom_alerts
WHERE (((servicemom_alerts.Body) Like "*" & [Enter Name] & "*"))
ORDER BY LTrim(Mid(Left([Body],InStr([Body],"logged on
to")-2),InStr([Body],"User ENTN\")+12)),
LTrim(Mid(Left([Body],InStr([Body],"logged on to")-2),InStr([Body],"User
ENTERPRISE\")+16));

Pretty much i have the query search through the body of an email for the
string between either "User ENTERPRISE\" or "User ENTN\" and the string
"logged on to"
The output of the qry will be a username of format AA##A (ex. AB30C)

What i was trying to do with the code is to resolve that username into the
full name of the user by accessing the GAL. As i said below, when i hardcode
a username into the code (Set objOutlookRecip = .Recipients.Add("AB30C")), i
get the correct resolved full name as the function return value.

What i am trying to do is get it so that the query output will populate the
.Recipients.Add("aaaaa") field and resolve each username output of the query
into the full name.

I hope i explained it enough, please let me know if you need more.

Thanks!
Klatuu said:
Sorry, I don't think I understand the question, can you give me more detail?
 
G

Guest

ok. At least you got the database connection working for me.
Thanks!

Klatuu said:
I don't think I am the right person to help with this. I will admit to
having almost no experience interfacing with Outlook. You might start a new
post with this question so others will read it.
Good Luck

bgcpen said:
Sorry, i'll try to make it clearer.
Here is my query SQL code.

SELECT servicemom_alerts.Body, LTrim(Mid(Left([Body],InStr([Body],"logged on
to")-2),InStr([Body],"User ENTN\")+12)) AS Expr1,
LTrim(Mid(Left([Body],InStr([Body],"logged on to")-2),InStr([Body],"User
ENTERPRISE\")+16)) AS Expr2,
IIf(Len([Expr1])>5,[Expr2],[Expr1]) AS Expr3
FROM servicemom_alerts
WHERE (((servicemom_alerts.Body) Like "*" & [Enter Name] & "*"))
ORDER BY LTrim(Mid(Left([Body],InStr([Body],"logged on
to")-2),InStr([Body],"User ENTN\")+12)),
LTrim(Mid(Left([Body],InStr([Body],"logged on to")-2),InStr([Body],"User
ENTERPRISE\")+16));

Pretty much i have the query search through the body of an email for the
string between either "User ENTERPRISE\" or "User ENTN\" and the string
"logged on to"
The output of the qry will be a username of format AA##A (ex. AB30C)

What i was trying to do with the code is to resolve that username into the
full name of the user by accessing the GAL. As i said below, when i hardcode
a username into the code (Set objOutlookRecip = .Recipients.Add("AB30C")), i
get the correct resolved full name as the function return value.

What i am trying to do is get it so that the query output will populate the
.Recipients.Add("aaaaa") field and resolve each username output of the query
into the full name.

I hope i explained it enough, please let me know if you need more.

Thanks!
Klatuu said:
Sorry, I don't think I understand the question, can you give me more detail?

:

Thanks for the quick response.
The code you sent me runs with no errors.
but i have one more question. The output of the query gives a username ,
how do i put that in this code to add the query output as a recipient?

With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("Query output")
objOutlookRecip.Type = olTo

:

Function sbSendMessage(userAlias As String)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
'Bad naming convention. obj should be for Objects, str should be for String
Dim objAlias As String
Dim data As DAO.Database
Dim names As DAO.Recordset
Dim qdf As QueryDef

Set data = CurrentDb
Set qdf = data.QueryDefs("QuerybyMailboxr")
qdf.Parameters(0) = userAlias 'Or whatever variable has the parameter value
Set names = qdf.OpenRecordset(dbOpenSnapshot)
'Debug.Print names.Updatable

Set objOutlook = CreateObject("Outlook.Application")

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("AB30C")
objOutlookRecip.Type = olTo

objAlias = objOutlookRecip.Resolve
userAlias = objOutlookRecip
End With
End Function

:

I am trying to use a query's results (a username) to look up the full name of
the individual from the GAL. When i hardcode the username in (ex. below
AB30C), the function will resolve and return the correct username. However,
when i try to run the openrecordset command, i get the runtime 3061 error
stating "too few parameters. Expected 1".

I tried putting my query code directly in instead of the name, but i still
get the same error.

Any help is greatly appreciated.

The code i am running is below:

Function sbSendMessage(userAlias As String)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim objAlias As String
Dim data As DAO.Database
Dim names As DAO.Recordset

Set data = CurrentDb
Set names = data.OpenRecordset("QuerybyMailbox", dbOpenSnapshot)
'Debug.Print names.Updatable

Set objOutlook = CreateObject("Outlook.Application")

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("AB30C")
objOutlookRecip.Type = olTo

objAlias = objOutlookRecip.Resolve
userAlias = objOutlookRecip
End With
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top