Send Email - Subject Line Contains Vaulues Of Two Fields

LarryB

Registered User.
Local time
Today, 16:02
Joined
Jun 19, 2012
Messages
66
Hi all,

I'm looking to reference to fields on a form when sending an email using code.

One field works fine once it has the focus but then trying to reference the second field I run into problems.

I could create another text box on the form and allow it's value to equal the two values of the other two fields, basically concatonate the two fields into one and then refer to that one field in my email code.

That option seems little messy but it will work.

Does anyone have any suggestions for a snazzy bit of code!!

Current Code

Field1.SetFocus
stSubject = "Email Send Test:- " & Field1.Text

Cheers

LarryB
 
Why do you have to SET FOCUS on the text field?? How many text field are you planning to concatenate? Could help if we could see a bit more coding..
 
Hi Paul, without the setfocus access gives out as soon as the code is stepped through

Error

Run-time error '2185': You can't reference a property or method unless the control has the focus

Here's my public email function I am calling. The two lines I am interested in are in red, not too de-similar to the amended code I supplied earlier

Public Function EMail()
Dim stSubject As String
Dim rst As DAO.Recordset
Dim strEmailAddress
Dim strEmailMessage

Set rst = CurrentDb.OpenRecordset("Select EMail From tblEmailList Where [uStatus] = 'Super'")
Do Until rst.EOF
strEmailAddress = strEmailAddress & rst("EMail") & ","
rst.MoveNext
Loop
[Forms]![frmaddedit]!tblFundAddEdit_Uptix_Code.SetFocus
stSubject = "MM Investment Application Approval Required Change:- " & [Forms]![frmaddedit]!tblFundAddEdit_Uptix_Code.Text
strEmailMessage = "Changed Fields As Follows:" & vbCrLf & ListOfUpdatedControls
strEmailAddress = Left(strEmailAddress, Len(strEmailAddress) - 1)
DoCmd.SendObject , , , strEmailAddress, , , stSubject, strEmailMessage
rst.Close
Set rst = Nothing
End Function

Basically I want to get another field called Investment Name added after the Uptix code so the code reads something like this

stSubject = "MM Investment Application Approval Required Change:- " & [Forms]![frmaddedit]!tblFundAddEdit_Uptix_Code.Text & " / " & [Forms]![frmaddedit]!tblFundAddEdit_Investment_Name.Text

Once it hits the Investname part of the code it looks for the focus

 
Just remove the .Text part and your good to go.
 
Try removing the .Text.. You do not need that.. remove it and see what happens..
 
.Text is the way to do it in classic vb. In Access you can only access the text property of a control that has the focus, thus you've runned into that runtime error.
 
Moishy is right.. thought .Text returns the same value as Me.[filedName] or [FieldName].Value, however it can do so only if it has the focus..
 
:banghead:

Thanks Moishy!! no need for the setfocus line and .text

stSubject = "MM Investment Application Approval Required Change:- " & [Forms]![frmaddedit]!tblFundAddEdit_Uptix_Code & " / " & [Forms]![frmaddedit]!tblFundAddEdit_Investment_Name

Thanks for the other inputs also
 

Users who are viewing this thread

Back
Top Bottom