Mailto command button in Access.

J

jake

Hi,

I have created a mailto control (command button) on a form in Access using
the following code:

Private Sub Command31_Click()
On Error GoTo Err_Command31_Click

Application.FollowHyperlink "Mailto:" &

Exit_Command31_Click:
Exit Sub

Err_Command31_Click:
MsgBox Err.Description
Resume Exit_Command31_Click

End Sub

What I'd like to know is whether I can modify this code so that if the
'email' field in the source table is blank, the command button becomes
inoperative, preferably greyed out (at the moment it opens a new email with
the address field blank).

Any help greatly appreciated.
 
R

Rob Parker

Change the operative line to:

If nz(len(,0) <> 0 then Application.FollowHyperlink "Mailto:" &
[email]

This will prevent an email message from opening if the [email] field is
either null, or a zero-length string.

Rob
 
M

Mark Phillipson

Also if you put the following code in the form's Curreny Event:

Me.Command31.Enabled = (Len(Me! & "") > 0)

--
HTH

Mark Phillipson

Free Add-Ins at; http://mphillipson.users.btopenworld.com/
[QUOTE="Rob Parker"]
Change the operative line to:

If nz(len([email],0) <> 0 then Application.FollowHyperlink "Mailto:" &
[email]

This will prevent an email message from opening if the [email] field is
either null, or a zero-length string.

Rob


[QUOTE="jake"]
Hi,

I have created a mailto control (command button) on a form in Access
using
the following code:

Private Sub Command31_Click()
On Error GoTo Err_Command31_Click

Application.FollowHyperlink "Mailto:" & [email]

Exit_Command31_Click:
Exit Sub

Err_Command31_Click:
MsgBox Err.Description
Resume Exit_Command31_Click

End Sub

What I'd like to know is whether I can modify this code so that if the
'email' field in the source table is blank, the command button becomes
inoperative, preferably greyed out (at the moment it opens a new email with
the address field blank).

Any help greatly appreciated.[/QUOTE]
[/QUOTE]
 
J

jake

Many thanks to both; I tried both methods and they work fine, although for
the reference of anyone else reading this, Rob's solution is missing a
parenthesis ")" after . Mark's is the one to use if you want the
control to be greyed out when inactive.

Thanks again,

Jake


[QUOTE="Mark Phillipson"]
Also if you put the following code in the form's Curreny Event:

Me.Command31.Enabled = (Len(Me![email] & "") > 0)

--
HTH

Mark Phillipson

Free Add-Ins at; http://mphillipson.users.btopenworld.com/
[QUOTE="Rob Parker"]
Change the operative line to:

If nz(len([email],0) <> 0 then Application.FollowHyperlink "Mailto:" &
[email]

This will prevent an email message from opening if the [email] field is
either null, or a zero-length string.

Rob


[QUOTE="jake"]
Hi,

I have created a mailto control (command button) on a form in Access
using
the following code:

Private Sub Command31_Click()
On Error GoTo Err_Command31_Click

Application.FollowHyperlink "Mailto:" & [email]

Exit_Command31_Click:
Exit Sub

Err_Command31_Click:
MsgBox Err.Description
Resume Exit_Command31_Click

End Sub

What I'd like to know is whether I can modify this code so that if the
'email' field in the source table is blank, the command button becomes
inoperative, preferably greyed out (at the moment it opens a new email with
the address field blank).

Any help greatly appreciated.[/QUOTE]
[/QUOTE]
[/QUOTE]
 
R

Rob Parker

Well spotted Jake,

That's what happens when I'm posting stuff at close to midnight - I should
go to bed instead ;-)

Rob

jake said:
Many thanks to both; I tried both methods and they work fine, although for
the reference of anyone else reading this, Rob's solution is missing a
parenthesis ")" after . Mark's is the one to use if you want the
control to be greyed out when inactive.

Thanks again,

Jake


[QUOTE="Mark Phillipson"]
Also if you put the following code in the form's Curreny Event:

Me.Command31.Enabled = (Len(Me![email] & "") > 0)

--
HTH

Mark Phillipson

Free Add-Ins at; http://mphillipson.users.btopenworld.com/
[QUOTE="Rob Parker"]
Change the operative line to:

If nz(len([email],0) <> 0 then Application.FollowHyperlink "Mailto:" &
[email]

This will prevent an email message from opening if the [email] field is
either null, or a zero-length string.

Rob


Hi,

I have created a mailto control (command button) on a form in Access
using
the following code:

Private Sub Command31_Click()
On Error GoTo Err_Command31_Click

Application.FollowHyperlink "Mailto:" & [email]

Exit_Command31_Click:
Exit Sub

Err_Command31_Click:
MsgBox Err.Description
Resume Exit_Command31_Click

End Sub

What I'd like to know is whether I can modify this code so that if the
'email' field in the source table is blank, the command button becomes
inoperative, preferably greyed out (at the moment it opens a new email
with
the address field blank).

Any help greatly appreciated.
[/QUOTE]
[/QUOTE][/QUOTE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top