Connecting Tech Pros Worldwide Forums | Help | Site Map

Strange Email Problem

simonmarkjones@gmail.com
Guest
 
Posts: n/a
#1: Nov 13 '05
I've got a button on my Access form which when i click loads a new
message in outlook.
I have got this to work on a number of forms. However it doesnt work on
on particular form in the database. And i cant understand why. It
deosnt make sense to me. When i click the button on this form i get a
Compile error - variable not defined. And it heighlights SW_SHOWNORMAL.


I have this in a module...

Public Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As
String, ByVal nShowCmd As Long) As Long

Here is the button code...

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click


Dim stext As String
Dim sAddedtext As String
If Len(cbemail) Then
stext = cbemail.Column(0)
End If

stext = "mailto:" & stext


If Len(sAddedtext) <> 0 Then
Mid$(sAddedtext, 1, 1) = "?"
End If


stext = stext & sAddedtext


' launch default e-mail program
If Len(stext) Then
Call ShellExecute(hwnd, "open", stext, vbNullString,
vbNullString, SW_SHOWNORMAL)
End If


Exit_Command0_Click:
Exit Sub


Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub


Please help someone. It doesnt seem logical to me that it works fine on
other forms but not this one.

Thanks in advance.


simonmarkjones@gmail.com
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Strange Email Problem


I'm guessing this form cant see the module that contains ShellExecute
for some reason

lylefair
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Strange Email Problem


One could guess that you have not declared
Public Const SW_SHOWNORMAL = 1
properly. As I recall one cannot make Public Declarations in classes
(in this case class may mean the form class module).

But this is guessing; a solution that may be frowned upon by those who
think MS will change the value of SW_SHOWNORMAL during the lifetime of
your application (or mine) is to hard code 1 in place of SW_SHOWNORMAL
so that the ShellExecute call becomes:
Call ShellExecute(hwnd, "open", stext, vbNullString, vbNullString, 1) .

Another solution might be to replace your call to the API function with
a one liner such as:

Application.FollowHyperlink "mailto:someone@domain.com"

but I am not sure this does everything you want as I can't tell what
sAddedText does (I think absolutely nothing but it's early in the
morning here and I have had only one cup of coffee, [so far].)

I have written quite a bit of API stuff but I don't recall finding a
reason to use the ShellExecute function. Perhaps there is some unique
capability of which I am unaware.

simonmarkjones@gmail.com
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Strange Email Problem


Thanks i will try that.

sAddedText is going to be used for adding text contained in textboxes
to be used for the body of the email. I've just left that bit out for
now

Cheers.

lylefair
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Strange Email Problem


I believe this group is filled with stories of problems with sending
e-mail with Outlook although I have not experienced them myself.
When I program sending e-mail I use CDO. It takes a little learning,
and is not particularly well presented, but it is simple and powerful:
http://msdn.microsoft.com/library/de...vr_cdo_top.asp

I'm not sure how committed to CDO MS is today, as many links lead
nowhere. But at this time it works very nicely.

simonmarkjones@gmail.com
Guest
 
Posts: n/a
#6: Nov 13 '05

re: Strange Email Problem


Thanks its working fine now.

Cheers

Closed Thread


Similar Microsoft Access / VBA bytes