Solved

VBA: Get text from combo box

Posted on 2007-03-18
4
1,158 Views
Last Modified: 2013-11-27
I have a form and am using the below code to try to send the text of a combo box using SMTP.  The email works, but it comes out like so:

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\EMAIL\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Maintenance Request

Submitted By: 3783
Time Requested: 3/17/2007 5:12:35 PM
Work Type: 3
Priority: 1
Location: Bay-A
Asset: BP-002
Problem Description:  vvvvv
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Now, this is basically what I want, but if you can tell, for example on the "Requestor" it shows a number.  In my combo, this is actually text, but the combo is bound to a number so I can understand why it does this.  Below is the code I have been trying to just use the actual TEXT of the combo versus its value with no success.  I have tried "me.reqid.text"  and "reqid.text" amoung other things with no success.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\VBA CODE\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

 Dim objCDOMail As Object
      Set objCDOMail = CreateObject("CDO.Message")
    objCDOMail.To = "--SOME EMAIL--"
    objCDOMail.FROM = "--SOME EMAIL--"
     objCDOMail.Subject = "MAINTENANCE REQUEST"
   objCDOMail.TextBody = "Maintenance Request" & vbCrLf & vbCrLf & "Submitted By: " & Me.reqid & vbCrLf & "Time Requested: " & Me.DateRec & vbCrLf & "Work Type: " & Me.WorkType & vbCrLf & "Priority: " & Me.WorkPriority & vbCrLf & "Location: " & Me.LocationNo & vbCrLf & "Asset: " & Me.AssetNo & vbCrLf & vbCrLf & "Problem Description: " & Me.ProbDesc    
    objCDOMail.configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objCDOMail.configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ""
    objCDOMail.configuration.Fields.Update      
    objCDOMail.Send
    Set objCDOMail = Nothing
0
Comment
Question by:chrisryhal
  • 2
4 Comments
 
LVL 6

Expert Comment

by:FrivolousSam
ID: 18743616
Why not look up the name using DLookup:

DLookup("[Name]", Requestors, [reqid] = " & Me.reqid)
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 18747269
I don't understand what you are refering too.  Could you please provide an example?  If you need the table name, its called "Employee's".
0
 
LVL 39

Accepted Solution

by:
stevbe earned 500 total points
ID: 18747852
If you are displaying the name in the combobox (and I bet you are) you need to determine which column it is in ... colyumns are 0 based so if the first (and bound column) is the ID and the second column is the name ...

 objCDOMail.From = Me.cboRequestor.Column(1)

Steve
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 18897465
stevbe,

That column thing is what I needed.  Thank you VERY much!!!!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now