Attaching Emails using Windows Dialog Box

  • Thread starter Thread starter Jamie Harbour
  • Start date Start date
J

Jamie Harbour

Hey

I need some code that will allow a user to browse for a file they want to
attach, i also would like it to be able to not attach a file if the user
doesnt browse & select one,

Thanks

Jamie
 
Jamie:

The first two KB articles show how to use the FileDialog object to select
files using a Windows Dialog Box. The third article shows how to create an
Outlook email that can optionally attach a document by looking at the length
of the attachment path supplied. I believe the FileDialog object was new to
Office 2002, so if you are using an earlier version you will have to use an
alternative method (let me know if this is the case).

http://support.microsoft.com/default.aspx?scid=kb;en-us;824272
http://support.microsoft.com/default.aspx?scid=kb;en-us;288543
http://support.microsoft.com/default.aspx?scid=kb;en-us;209948

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Hey

I need some code that will allow a user to browse for a file they want to
attach, i also would like it to be able to not attach a file if the user
doesnt browse & select one,

Thanks

Jamie
 
David,

Thank you for the file dialog code that is working just as i need, the only
problem i have is that the Email Module supplied will not accept the listbox
as the source for the attachments, it comes back with "Run Time Error 438 -
Object does not support property or method" I also tried transferring the
contents of the Listbox to a text field but it wont accept that either,

Any thoughts would be greatly appreciated as this is the last peice to the
puzzle,

Thanks

Jamie
 
Jamie:

It would be helpful to see the code you are using in integrating the listbox
with the email module. It would also be beneficial to know more about the
properties of the listbox (i.e. Row Source Type, Row Source, Bound Column,
Column Count, etc.).

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


David,

Thank you for the file dialog code that is working just as i need, the only
problem i have is that the Email Module supplied will not accept the listbox
as the source for the attachments, it comes back with "Run Time Error 438 -
Object does not support property or method" I also tried transferring the
contents of the Listbox to a text field but it wont accept that either,

Any thoughts would be greatly appreciated as this is the last peice to the
puzzle,

Thanks

Jamie
 
The code i am using to attach the email is from the 3rd link you posted and
is below,

'Add the attachment to the e-mail message.
If Not IsMissing(Forms!frmMailshot!FileAttach) Then
Set objOutlookAttach = .Attachments.Add(Forms!frmMailshot!FileAttach)
End If

The properties of the listbox are:

RowSource Type = ValueList
Row Source= BLANK
Bound Column= 1
Column Count= 1

Thanks
Jamie
 
Jamie:

Apparently the Add method has difficulty resolving the reference to the
listbox (I am assuming "FileAttach" is the name of your listbox). There are
a couple of ways to handle this. One is to use the CStr function to resolve
the listbox reference. For example:

If Not IsMissing(Forms!frmMailShot!FileAttach) Then
Set objOutlookAttach =
..Attachments.Add(CStr(Forms!frmMailShot!FileAttach))
End If

Two, you could call the SendMessage routine with the name of the listbox and
use the AttachmentPath parameter of the function as in the KB article. For
example:

SendMessage (Forms!frmMailShot!FileAttach)

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


The code i am using to attach the email is from the 3rd link you posted and
is below,

'Add the attachment to the e-mail message.
If Not IsMissing(Forms!frmMailshot!FileAttach) Then
Set objOutlookAttach = .Attachments.Add(Forms!frmMailshot!FileAttach)
End If

The properties of the listbox are:

RowSource Type = ValueList
Row Source= BLANK
Bound Column= 1
Column Count= 1

Thanks
Jamie
 
David,

I tried option 1 and i get runtime error 94, invalid use of null and it
points to the line with the CStr function in it, and i dont really want to
use option 2 because i want the process to be automated and so the user
doesnt have to use VB,

any idea would help,

Thanks
 
Jamie:

You can just wrap the code in an IF statement that checks for a null value
rather than using the IsMissing function which only applies to procedure
arguments. If the value is null, it means you have not selected a file in
the listbox. For example:

If Not IsNull(Forms!frmMailShot!FileAttach) Then
Set objOutlookAttach =
..Attachments.Add(CStr(Forms!frmMailShot!FileAttach))
End If

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


David,

I tried option 1 and i get runtime error 94, invalid use of null and it
points to the line with the CStr function in it, and i dont really want to
use option 2 because i want the process to be automated and so the user
doesnt have to use VB,

any idea would help,

Thanks
 
Ok, i replaced the code with the code you gave me know it just does not
attach anything, was it meant to replace the code in the module or add into
it?
 
Jamie:

It was meant to replace the code in the module. If you do not select a item
in the listbox then it will not attach anything. I did test the code and it
does work.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Ok, i replaced the code with the code you gave me know it just does not
attach anything, was it meant to replace the code in the module or add into
it?
 
Its not taking it, I have tried the code using the list box and it does not
attach anything and i have tried the code on a text box that has the path
transferred to it from the list box and when i dont attach anything it says
it can find the file.
 
Jamie:

Without more seeing your code and having more specifics of how your form is
setup, it is difficult to know where the issue lies.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Its not taking it, I have tried the code using the list box and it does not
attach anything and i have tried the code on a text box that has the path
transferred to it from the list box and when i dont attach anything it says
it can find the file.
 
Back
Top