Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

attachment field using automation of outlook

Status
Not open for further replies.

JonEx

Programmer
Joined
Feb 26, 2004
Messages
21
Location
BB
hey,
ok i have a form in access that can send emails using automation of outlook. i can type a message and a subject and click send . and outlook sends it, now i was wondering if i can have an attachment field within this form as well?
this is the module for the sendmsg function
************************************************************
Option Compare Database

Global Const STR_NULL1 As String = ""

Public Sub SendMsg(strSubject As String, _
strBody As String, _
strTo As String, _
Optional strCC As String = STR_NULL1, _
Optional strBCC As String = STR_NULL1)

Dim oLapp As Outlook.Application
Dim oItem As Outlook.MailItem

Set oLapp = CreateObject("Outlook.Application")
Set oItem = oLapp.CreateItem(0)
With oItem
.Subject = strSubject
.To = strTo
If Not IsMissing(strCC) And strCC <> STR_NULL1 Then
.CC = strCC
End If
If Not IsMissing(strBCC) And strBCC <> STR_NULL1 Then
.BCC = strBCC
End If
.Body = strBody
.Send
End With
Set oLapp = Nothing
Set oItem = Nothing

End Sub

************************************************************


 
the command line is:

.Attachments.Add path

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
hey thanks robert,
but what if i wanted to attach the file using a command button, this is what i have so far

************************************************************
Private Sub cmdBrowse_Click()
On Error GoTo err_cmdBrowse

Me.txtAttachment = GetOpenFile_CLT("C:\", "Select a File to Attach.")
Me.txtAttachment = LCase(Me.txtAttachment)

If Me.txtAttachment <> STR_NULL1 And Not IsNull(Me.txtAttachment) Then
Me.txtAttachmentAlias.Enabled = True
Me.txtAttachmentAlias.SetFocus
Else
Me.txtAttachmentAlias.Enabled = False
End If

exit_cmdBrowse:
Exit Sub

err_cmdBrowse:
MsgBox err.Description
Resume exit_cmdBrowse
End Sub
************************************************************
where STR_NULL1 is a global constant.
 
Do you mean you want to add an attachment to the email with a separate button??? I don't know how to do that....I would simply add some code to ask the user if they want to add an attachment and include your above code if they do....



Start email code

If msgbox("Do you wish to add attachment?", vbyesno, "Add Attachment?") = vbyes Then
add attachment code
End If

rest of email code


=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top