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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending e-mail from access

Status
Not open for further replies.

monomax

Technical User
Jan 23, 2003
10
GB
I was looking at a closed thread 702-396121 and am trying to send an email from my database using the following code as a template:

Private Sub Command10_Click()
Dim email, ref, origin, destination, notes As String

'***set references from your form
email = Me!email
ref = Me!ref
origin = Me!origin
destination = Me!destination
notes = Me!notes

'***set up the transaction that will format and send email
'***True at the end of the statement allows the email to be
'***edited before sent. change to False, and the email is
'***sent without edit
DoCmd.SendObject acSendForm, , acFormatTXT, email, , , ref & " " & origin & " " & destination, notes, True

End Sub

Trouble is, my form has fields containing spaces and a forward slash (/) ie

space booked
client/brand

Does anyone know how to cope with these special characters?

Thanks
 
Hi, monomax,

To refer to fields whose names contain special characters (I think that's what you are asking), simply enclose them in square brackets, i.e. [blue]Me![space booked][/blue].

On another note, your variable declaration:
Code:
Dim email, ref, origin, destination, notes As String
...only declares [blue]notes[/blue] as a string type variable, all the others are variants! Perhaps that's what you intended, but if not, then:
Code:
Dim email [blue]As String[/blue], ref [blue]As String[/blue], origin [blue]As String[/blue], [green]'etc.[/green]
OR (my preferred method)
Code:
Dim email As String
Dim ref As String
Dim origin As String
[green]'etc.[/green]
HTH,

Ken S.
 
Thanks Eupher,

I note your comments about the variable declaration. That was also picked up on the closed thread 702-396121 but nathan1967(Technical User) said "My intent was not to declare Variants. I guess I didn't catch it since everyting worked." It's worked for me too and, to be honest, I don't really understand the difference. (There are 86 pages in that thread, so it's hard to follow).

Your brackets have certainly solved the problem about my special characters, so thanks for that, and the email is now working.

However, not only does the email take about 5 seconds to appear, but it also includes a text attachment of the all the requested records in the form, which I don't really want.

Any clues?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top