Send Email "Body Message.

josros60

Registered User.
Local time
Today, 06:50
Joined
Mar 10, 2011
Messages
73
Hi,

I have this code that i want send as body message in email but i want to pickup the company name according the company i am sending the invoice,

but giving me error 2465 cannot find the field,

Here it's the code:

Code:
Private Sub btnSend_Click()
    Dim oApp As New Outlook.Application
    Dim oEmail As Outlook.MailItem
    
    Set oEmail = oApp.CreateItem(olMailItem)
    
    oEmail.To = Me.txtTo
    oEmail.subject = Me.txtSubject
    oEmail.Body = "Here is the monthly invoice # for " & [Company Name] & "." & "Please confirm if we may collect the payment from your wallet.Please contact me if you have any questions.Thanks,"

when give me the above error and click debug it highlight this line:

Code:
"Here is the monthly invoice # for " & [Company Name] & "." & "Please confirm if we may collect the payment from your wallet.Please contact me if you have any questions.Thanks,"

thanks
 
Presuming it's on the form, I'd use:

Me.TextboxName
 
As Paul stated - You can't refer to [Company Name] in the middle of the Outlook Object Body reference.

Set it in a string before hand and refer to the string, something like

Code:
Dim sBody as String

sBody = "Here is the monthly invoice # for " & [Company Name] & "." & "Please confirm if we may collect the payment from your wallet.Please contact me if you have any questions.Thanks,"

Debug.Print sBody       [COLOR="Green"] 'This will show you what is pulled in in the immediate window[/COLOR]

oEmail.Body = sBody
 
Thank you. I tried the suggested code below, but it gets me the id number instead of company name, how can i make to get the Customer name instead.

Code:
Private Sub btnSend_Click()
    Dim oApp As New Outlook.Application
    Dim oEmail As Outlook.MailItem
    Dim sBody As String
    Set oEmail = oApp.CreateItem(olMailItem)
    
    oEmail.To = Me.txtTo
    oEmail.subject = Me.txtSubject
    sBody = "Here is the monthly invoice # for " & Me.txtCompany & "." & "Please confirm if we may collect the payment from your wallet.Please contact me if you have any questions.Thanks,"
    'oEmail.Body = "Here is the monthly invoice # for " & [Company Name] & "." & "Please confirm if we may collect the payment from your wallet.Please contact me if you have any questions.Thanks,"
    
       
    If Len(Me.txtAttachment) > 0 Then
        oEmail.Attachments.Add Me.txtAttachment.Value
    End If
    With oEmail
      '  If Not IsNull(.To) And Not IsNull(.subject) And Not IsNull(.Body) Then
          .Display
            MsgBox "Remember to attach Invoice(s)"
       End With
      
   oEmail.Body = sBody
   Debug.Print sBody
End Sub

thank you very much.
 
I suspect you've got a lookup field? Is txtCompany a textbox or a combo? If it's a combo, try referring to the column with name:

Me.txtCompany.Column(x)
 
it's a combo, how do i know the column number?

thanks
 
Look at the row source. The first column displayed is 0, second is 1, etc.
 
Sorry, i have one more question if you please can help me,

depending on the customer, some of them already approved us to withdraw from their wallet, and other one has to confirm

how can i make that to work,

here are the two messages:

1.
Code:
="Here is the monthly invoice # for " & Me.txtCompany.Column(1) Please confirm if we may collect the payment from your wallet." & vbCrLf & vbCrLf & "Please contact me if you have any questions.Thanks,"

2.

Code:
="Here is the monthly invoice # for " & Me.txtCompany.Column(1) As per your instructions we will withdraw the amount from your loading wallet. " & vbCrLf & vbCrLf & "Please contact me if you have any questions.Thanks,"

i hope you can give me an idea how to make this work,

thanks
 
How do you know which is which? Presuming a field on the form, use an If/Then/Else to add the appropriate text.
 
Because this switching from excel to Access and we have a list of customer that approve to withdraw, so in excel type message depending on the customer.


how can i use an If/Then/Else to add the appropriate text.

any idea?
 
Code:
If WhateverTheAppropriateTestIs Then
  sBody = "Here is one string"
Else
  sBody = "Here is the other"
End If
 
Re: Send Email "Body Message. (SOLVED)

Thank you for all your help.

everything works.
 

Users who are viewing this thread

Back
Top Bottom