Output of query as variable in code

B

bgcpen

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. 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") line and resolve each username output of the query
into the full name.

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));

Here is my function code:

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 strAlias As String
Dim data As DAO.Database
Dim names As DAO.Recordset
Dim qdf As QueryDef

Set data = CurrentDb
Set qdf = data.QueryDefs("QuerybyMailbox")
qdf.Parameters(0) = Expr3 'this is the equation that gets the username in
the query
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

strAlias = 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