PDA

View Full Version : How to use a string variable for amending an email message



Allovercars
11-04-2013, 10:52 AM
Good afternoon,

I want to use a variable (text) to complete an email but I cannot manage to insert the variable value in the email text message.
In the example here below I have 2 string variables : VehicleType and VehicleVin. I would like to use these information to update the text in my email message that should become "Vehicle profile"& VehicleType. But I cannot make it work

Private Sub CmdVehicleProfileEMail_Click()
On Error GoTo CmdVehicleProfileEmail_Click_Err
Dim VehicleNumber As Integer
Dim VehicleType As String
Dim VehicleVin As String
VehicleNumber = [TFleetRef]
DoCmd.OpenForm "FQTVehicleProfileEMail", acNormal
DoCmd.ApplyFilter "", "TFleetRef=" & VehicleNumber
DoCmd.SendObject acForm, "FQTVehicleProfileEMail", "PDFFormat(*.pdf)", "", "", "", "Profile vehicle"
DoCmd.Close
CmdVehicleProfileEMail_Click_Exit:
Exit Sub
CmdVehicleProfileEmail_Click_Err:
MsgBox "Your e-mail has not been sent"
DoCmd.Close acForm, "FQTVehicleProfileEMail"
DoCmd.Close acForm, "FQTVehicleProfile"
Resume CmdVehicleProfileEMail_Click_Exit
End Sub

Can somebody help it ?

Thanks and regards

SoftwareMatt
11-05-2013, 04:55 AM
Try this


DoCmd.SendObject acForm, "FQTVehicleProfileEMail", "PDFFormat(*.pdf)", "", "", "", "Profile vehicle", "Vehicle profile" & VehicleType

Allovercars
11-05-2013, 05:36 AM
Hello and thanks for the message. I have changed it. Now I just get the raw text "Vehicle profile" on the Outlook message. The value of the variables are not brought to the message. Thanks a lot in and any case.

Regards, Xavier

HiTechCoach
11-05-2013, 09:26 AM
You are not setting any values in the variables VehicleType and VehicleVin. Where do the values come from?

Try something like this:

NOTE: You will need to update the code below for the two lines ending with the comment <<<< get value from somewhere



Private Sub CmdVehicleProfileEMail_Click()
On Error GoTo CmdVehicleProfileEmail_Click_Err
Dim VehicleNumber As Integer
Dim VehicleType As String
Dim VehicleVin As String
VehicleNumber = [TFleetRef]

' set the values here

VehicleType = "" ' <<<< get value from somewhere
VehicleVin = "" ' ' <<<< get value from somewhere

DoCmd.OpenForm "FQTVehicleProfileEMail", acNormal
DoCmd.ApplyFilter "", "TFleetRef=" & VehicleNumber
DoCmd.SendObject acForm, "FQTVehicleProfileEMail", "PDFFormat(*.pdf)", "", "", "", "Profile vehicle", "Vehicle Type: " & VehicleType & " - VIN " & VehicleVin
DoCmd.Close
CmdVehicleProfileEMail_Click_Exit:
Exit Sub
CmdVehicleProfileEmail_Click_Err:
MsgBox "Your e-mail has not been sent"
DoCmd.Close acForm, "FQTVehicleProfileEMail"
DoCmd.Close acForm, "FQTVehicleProfile"
Resume CmdVehicleProfileEMail_Click_Exit
End Sub