Pull name form table using code

G

Guest

I am using the code below to generate and send a email. What I need help in
doing is pull the First Name of the empolyee from tblEmployee and add it
where I have the Currentuser(). I am not sure how to do this and hope
someone can help me with this.
tblEmployee is set as [AutoID],[Last],[First],[UserID]

On Error GoTo Err_cmdSubmit_Click

Dim stDocName As String

stDocName = "tblvacation"
DoCmd.SendObject acSendNoObject, stDocName, , "(e-mail address removed)", , ,
("VACATION REQUEST: " & Me![vacationstart] & _
" thru " & Me![vacationend]), ("Randy," & Chr(10) & "I would like to
schedule these days off for my vacation " & Me![vacationstart] & _
" thru " & Me![vacationend] & ". " & Chr(10) & "Thank you." & Chr(10) &
currentuser()), , True
approvalwaiting.Value = False

Exit_cmdSubmit_Click:
Exit Sub

Err_cmdSubmit_Click:
MsgBox "You cancelled this operation, your email was not sent.", 0, "
EMAIL NOT SENT!"
Exit Sub
Resume Exit_cmdSubmit_Click
 
S

Scott McDaniel

DoCmd.SendObject acSendNoObject, stDocName, , "(e-mail address removed)", , ,
("VACATION REQUEST: " & Me![vacationstart] & _
" thru " & Me![vacationend]), ("Randy," & Chr(10) & "I would like to
schedule these days off for my vacation " & Me![vacationstart] & _
" thru " & Me![vacationend] & ". " & Chr(10) & "Thank you." & Chr(10) &
Dlookup("First", "tblEmployee", "UserID='" & YourCurrentUser & "'"), , True
approvalwaiting.Value = False

You didn't specify HOW you are determining the currentuser ... therefore
"YourCurrentUser" is simply a placeholder, and you would need to change this
(and possibly the UserID in the DLookup method) to match the fields you are
using to determine the current user. If you haven't implemented User Level
Security, then currentuser ALWAYS returns "Admin" ... if you have some sort
of login scheme where you're capturing the UserID when users login the use
that value.
 
G

Guest

Scott,
Work perfect...
Thanks!!

Scott McDaniel said:
DoCmd.SendObject acSendNoObject, stDocName, , "(e-mail address removed)", , ,
("VACATION REQUEST: " & Me![vacationstart] & _
" thru " & Me![vacationend]), ("Randy," & Chr(10) & "I would like to
schedule these days off for my vacation " & Me![vacationstart] & _
" thru " & Me![vacationend] & ". " & Chr(10) & "Thank you." & Chr(10) &
Dlookup("First", "tblEmployee", "UserID='" & YourCurrentUser & "'"), , True
approvalwaiting.Value = False

You didn't specify HOW you are determining the currentuser ... therefore
"YourCurrentUser" is simply a placeholder, and you would need to change this
(and possibly the UserID in the DLookup method) to match the fields you are
using to determine the current user. If you haven't implemented User Level
Security, then currentuser ALWAYS returns "Admin" ... if you have some sort
of login scheme where you're capturing the UserID when users login the use
that value.

Raj said:
I am using the code below to generate and send a email. What I need help
in
doing is pull the First Name of the empolyee from tblEmployee and add it
where I have the Currentuser(). I am not sure how to do this and hope
someone can help me with this.
tblEmployee is set as [AutoID],[Last],[First],[UserID]

On Error GoTo Err_cmdSubmit_Click

Dim stDocName As String

stDocName = "tblvacation"
DoCmd.SendObject acSendNoObject, stDocName, , "(e-mail address removed)", , ,
("VACATION REQUEST: " & Me![vacationstart] & _
" thru " & Me![vacationend]), ("Randy," & Chr(10) & "I would like to
schedule these days off for my vacation " & Me![vacationstart] & _
" thru " & Me![vacationend] & ". " & Chr(10) & "Thank you." & Chr(10) &
currentuser()), , True
approvalwaiting.Value = False

Exit_cmdSubmit_Click:
Exit Sub

Err_cmdSubmit_Click:
MsgBox "You cancelled this operation, your email was not sent.", 0, "
EMAIL NOT SENT!"
Exit Sub
Resume Exit_cmdSubmit_Click
 

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