473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Hyperlinks, input masks, and sending email in Access 2007

269 256MB
I've been trying to figure this out for three weeks. I've been sleeping on it. Not getting answers, just losing sleep. ;-)

In a table, I have a field COMPANY_EMAIL. In this field I want to allow up to 8 characters, use the same domain always, and in a form be able to click and open an email to this customer. I have tried this in numerous ways, and I think it's occuring to me finally I can't do everything in one place. I think I might need a button.

I'm using <aaaaaaaa!"@domain"."com" in my input mask. This is pretty good, except if the address is only 4 letters, it leaves 4 spaces on the left side. I don't like that. Ideas?

I have put a button next to the email field in the form (as opposed to trying to use a hyperlink and an input mask...that got me nowhere fast). Right now the button is just sitting there. I know I'll need some code probably behind "on click" but I don't know what to put there to open an email to the address specified. Ideas??

I'm aware of the mailto: part...I tried to use one field as a hyperlink with the mailto: and domain.com all in the input mask (to end up with mailto:xxx@domain.com) but sometimes, say for instance if the address was mbo@domain.com, the "m" would replace the "m" in mailto: and the "bo" would go in as the email address. When I chose an address that would go in correctly and clicked it in the form, it would never open an email anyway...so I'm trying to come up with a new plan...like the button plan above.

I need your guidance/ideas, so throw some at me!!!
Thank you so much for your time, patience, and brains! :-)
Oct 21 '09 #1

✓ answered by ADezii

The following code will:
  1. Perform minimal validation on the E-Mail Address as entered into the [COMPANY_EMAIL] Field.
  2. Open a Session of Microsoft Outlook with the chosen E-Mail Address as entered into the [COMPANY_EMAIL] Address Field as the To: segment.
  3. Leave the Subject and Body empty for the User to fill in.
  4. Simply fill in the missing info then Send.
  5. Be sure to set a Reference to the Microsoft Outlook XX.X Object Library before you attempt to execute this code.
Expand|Select|Wrap|Line Numbers
  1. 'YOU MUST FIRST SET A REFERENCE TO THE OUTLOOK XX.X OBJECT LIBRARY
  2. Dim oLook As Object
  3. Dim oMail As Object
  4. Dim olns As Outlook.Namespace
  5. Dim strEMailAddress As String
  6. Dim txtEMail As TextBox
  7.  
  8. Set txtEMail = Me![COMPANY_EMAIL]
  9.  
  10. 'Let's at least perform Minimal Validation
  11. If IsNull(txtEMail) Then
  12.   MsgBox "No E-Mail Address listed", vbCritical, "Missing E-Mail Address"
  13.     txtEMail.SetFocus
  14.       Exit Sub
  15. ElseIf InStr(txtEMail, "@") = 0 Or InStr(txtEMail, ".") = 0 Then
  16.   MsgBox "Invalid E-Mail Address", vbCritical, "Invalid E-Mail Address"
  17.     txtEMail.SetFocus
  18.       Exit Sub
  19. End If
  20.  
  21. strEMailAddress = txtEMail
  22.  
  23. DoCmd.Hourglass True
  24.  
  25. Set oLook = CreateObject("Outlook.Application")
  26. Set olns = oLook.GetNamespace("MAPI")
  27. Set oMail = oLook.CreateItem(0)
  28.  
  29. With oMail
  30.   .To = strEMailAddress
  31.   .Body = ""
  32.   .Subject = ""
  33.     .Display
  34. End With
  35.  
  36. Set oMail = Nothing
  37. Set oLook = Nothing
  38.  
  39. DoCmd.Hourglass False

21 7913
NeoPa
32,556 Expert Mod 16PB
I'm not too hot on mailing from an application. Whenever I tried it the side issues put me off. There are a whole bunch of threads (some in which I'm involved) which deal with security problems etc etc.

Having said that, I can certainly help with the interface and how to make up, and even store, the email addresses.

Let's start with a question. Do you really want the "@blah blah.com" bit to be entered by the operator and/or saved? I would consider including that as static on the form in a Label control and just dealing with the name part in the interface.
Oct 21 '09 #2
DanicaDear
269 256MB
I could definetely be convinced to go one way or the other. You see, I am just doing what I can comprehend on Access...I'm not yet familiar with all the other, better ways things can be done. I'm learning A LOT here on BYTES. In fact, BYTES has probably made this project a success instead of a failure for me.
So, it seems you encourage me to just deal with the first part of the email address. I can go that route, I'll just need some guidance on how to get the @domain.com connected. The people that will be using the DB are far less computer savvy than I am, so I wanted to make it easy for them to open an email to the customer. Persuade me in a direction...your advice so far has been phenominal. :-)
Oct 22 '09 #3
ADezii
8,834 Expert 8TB
@DanicaDear
Danica, what is your E-Mail Client (Outlook, Internet Explorer, etc.)?
Oct 22 '09 #4
DanicaDear
269 256MB
Danica, what is your E-Mail Client (Outlook, Internet Explorer, etc.)?
I use MS Outlook. Thanks.
Oct 22 '09 #5
ADezii
8,834 Expert 8TB
It should be a relatively simple matter to automate the process of send an E-Mail to a specific Address within Outlook, but first:
  1. Where are you obtaining the E-Mail Address from? If it is a Field on a Form, then what is the Field Name (txtEMailAddress, txtCompany, etc.)?
  2. Do you want the E-Mail automatically sent with Default Body Text and Subject, or do you simply want the Outlook Window open with the To: and Subject: automatically filled in, and leave the Body: to you?, etc...
Oct 22 '09 #6
DanicaDear
269 256MB
1. Field COMPANY_EMAIL in table HOTSTICK_CUSTOMERS and form HOTSTICK_CUSTOMERS. (I was educated on better naming after I named everything...will do better in the future.) Also note, I changed the name to appear as "Email" to the user. But I think the program writer is mostly concerned with the name that shows in design view...which is COMPANY_EMAIL.
2. I want to open an email and leave both the subject and the body as the user's responsibility. I can see where I might eventually in the future want to automate things much more but for now I'm just a beginner and I could spend a year writing this DB if I don't watch it. ;-) (Why am I suddenly laughing out loud?)

The lab freqeuntly sends out saved emails where sometimes it would likely be easier to copy and paste the email address from Access to Outlook. On other occasions, they might want to send a unique email and that is where clicking the email address in the Access program would be more helpful. That's why I initially tried to create one text box with the domain attached and make it a hyperlink...so I could have flexibility to copy or click. I'm still open and conviceable. You people know lots more than me. I tend to take good advice. Thanks again, Danica
Oct 22 '09 #7
ADezii
8,834 Expert 8TB
The following code will:
  1. Perform minimal validation on the E-Mail Address as entered into the [COMPANY_EMAIL] Field.
  2. Open a Session of Microsoft Outlook with the chosen E-Mail Address as entered into the [COMPANY_EMAIL] Address Field as the To: segment.
  3. Leave the Subject and Body empty for the User to fill in.
  4. Simply fill in the missing info then Send.
  5. Be sure to set a Reference to the Microsoft Outlook XX.X Object Library before you attempt to execute this code.
Expand|Select|Wrap|Line Numbers
  1. 'YOU MUST FIRST SET A REFERENCE TO THE OUTLOOK XX.X OBJECT LIBRARY
  2. Dim oLook As Object
  3. Dim oMail As Object
  4. Dim olns As Outlook.Namespace
  5. Dim strEMailAddress As String
  6. Dim txtEMail As TextBox
  7.  
  8. Set txtEMail = Me![COMPANY_EMAIL]
  9.  
  10. 'Let's at least perform Minimal Validation
  11. If IsNull(txtEMail) Then
  12.   MsgBox "No E-Mail Address listed", vbCritical, "Missing E-Mail Address"
  13.     txtEMail.SetFocus
  14.       Exit Sub
  15. ElseIf InStr(txtEMail, "@") = 0 Or InStr(txtEMail, ".") = 0 Then
  16.   MsgBox "Invalid E-Mail Address", vbCritical, "Invalid E-Mail Address"
  17.     txtEMail.SetFocus
  18.       Exit Sub
  19. End If
  20.  
  21. strEMailAddress = txtEMail
  22.  
  23. DoCmd.Hourglass True
  24.  
  25. Set oLook = CreateObject("Outlook.Application")
  26. Set olns = oLook.GetNamespace("MAPI")
  27. Set oMail = oLook.CreateItem(0)
  28.  
  29. With oMail
  30.   .To = strEMailAddress
  31.   .Body = ""
  32.   .Subject = ""
  33.     .Display
  34. End With
  35.  
  36. Set oMail = Nothing
  37. Set oLook = Nothing
  38.  
  39. DoCmd.Hourglass False
Oct 22 '09 #8
NeoPa
32,556 Expert Mod 16PB
@DanicaDear
OK. For the sake of this we'll assume that the domain part of the email address is to be @Domain.com. We can also work on an eight character name part if you like, but I expect you can handle that in the design of your form (and control). You would need to change what type of data is expected in [COMPANY_EMAIL], as well as add a Label control after it which displayed the domain name. The Label control (Let's call it lblDomain) would display @Domain.com. This is easily changed in Design View for a different domain of course.

What I'm suggesting here is easily incorporated into ADezii's code. It would simply replace line #8.
Expand|Select|Wrap|Line Numbers
  1. Set txtEMail = Me![COMPANY_EMAIL]
All we do really is add the domain address (conveniently found in lblDomain) to the end of [COMPANY_EMAIL] to produce the full address :
Expand|Select|Wrap|Line Numbers
  1. Set txtEMail = Me.[COMPANY_EMAIL] & Me.lblDomain.Caption
Otherwise, I'm sure ADezii's code will work fine for you (not that it wouldn't without this suggestion you understand).
Oct 22 '09 #9
DanicaDear
269 256MB
Thanks everyone. I'm off til Monday. Will get restarted then. I'm soooo tempted to try this right away (because I will admit this project is kind of exciting). However, 40 hours of Access is enough in a week so I definitely need to take my breaks so I don't get burnt out. (Plus I have the cutest little one year old!) :-)
Y'all have a nice weekend.
Oct 23 '09 #10
NeoPa
32,556 Expert Mod 16PB
Sounds like fun Danica. Go and enjoy your weekend (and your family). We'll all be here again on Monday I expect ;)
Oct 23 '09 #11
DanicaDear
269 256MB
Hey GUYS! LOL.
I'm trying to get the email thing to work. When I tried ADezii's code with my email address I got a warning box that said "Not a valid email address." Then I tried NeoPa's suggestion and I get the debugger which takes me to NeoPa's line #8. I think I did all the suggestions you made NeoPa...but something isn't right. (Set the reference to Outlook, properly named the form, etc etc). Can you help? Thanks!
Attached Files
File Type: zip SHOPS102209b.zip (2.19 MB, 145 views)
Oct 26 '09 #12
ChipR
1,287 Expert 1GB
ADezii's code can not produce that message. How much have you changed it?
Oct 26 '09 #13
DanicaDear
269 256MB
On the HOTSTICK_CUSTOMERS form, all I did was add the label "@southernco.com", change the name and picture on the button, attach ADezii's code at the OnClick event, and change the line number 8 from
Expand|Select|Wrap|Line Numbers
  1. Set txtEMail = Me![COMPANY_EMAIL] 
to
Expand|Select|Wrap|Line Numbers
  1. Set txtEMail = Me.[COMPANY_EMAIL] & Me.lblDomain.Caption
If you find worse than that...I did it on accident. :-)

The form only lists 13 customers and a few of those *do* have bad email addresses...but you will be able to tell what's correct just by looking. Those that are screwed up are due to me playing with hyperlinks previously. I have only tried to use the button on the addresses that are valid.
Oct 26 '09 #14
ADezii
8,834 Expert 8TB
@DanicaDear
Completely replace your code with the following code (Copy and Paste), and all should be well in your world.
Expand|Select|Wrap|Line Numbers
  1. 'YOU MUST FIRST SET A REFERENCE TO THE OUTLOOK XX.X OBJECT LIBRARY
  2. Dim oLook As Object
  3. Dim oMail As Object
  4. Dim olns As Outlook.NameSpace
  5. Dim strEMailAddress As String
  6. Dim strEMail As String
  7.  
  8. 'Set txtEMail = Me.[COMPANY_EMAIL]
  9. strEMail = Me.[COMPANY_EMAIL] & Me.lblDomain.Caption
  10.  
  11. 'Let's at least perform Minimal Validation
  12. If IsNull(Me![COMPANY_EMAIL]) Then
  13.   MsgBox "No E-Mail Address listed", vbCritical, "Missing E-Mail Address"
  14.     Me![COMPANY_EMAIL].SetFocus
  15.       Exit Sub
  16. ElseIf InStr(strEMail, "@") = 0 Or InStr(strEMail, ".") = 0 Then
  17.   MsgBox "Invalid E-Mail Address", vbCritical, "Invalid E-Mail Address"
  18.     txtEMail.SetFocus
  19.       Exit Sub
  20. End If
  21.  
  22. DoCmd.Hourglass True
  23.  
  24. Set oLook = CreateObject("Outlook.Application")
  25. Set olns = oLook.GetNamespace("MAPI")
  26. Set oMail = oLook.CreateItem(0)
  27.  
  28. With oMail
  29.   .To = strEMail
  30.   .Body = ""
  31.   .Subject = ""
  32.     .Display
  33. End With
  34.  
  35. Set oMail = Nothing
  36. Set oLook = Nothing
  37.  
  38. DoCmd.Hourglass False
Oct 26 '09 #15
ChipR
1,287 Expert 1GB
Ok, let's look at what the code actually does, rather than just copy and paste. The line number 8 that you changed appends the "@southernco.com" onto the [COMPANY_EMAIL], so I will assume the [COMPANY_EMAIL] you are testing with is just something like a name.
Look at lines 10 through 19. You are checking to verify that [COMPANY_EMAIL] contains both a "@" and "." symbol, and it clearly doesn't since you are going to paste them on the end later. Perhaps instead, you should verify that it doesn't have those characters.
@ChipR
Oct 26 '09 #16
DanicaDear
269 256MB
Oh my goodness...you people ROCK!!!!!!!!!!!!
ChipR...thank you for your hints. They are helping.
ADezii, thanks for the code!
NeoPa, thanks for the good explanations.
I'm out of questions for now but I'm sure I'll be back with a new string very soon! LOL. (Some of you may not want to open a new can of worms. hahaha.)
Oct 26 '09 #17
NeoPa
32,556 Expert Mod 16PB
You do keep us somewhat busy Danica, but I admit to feeling pretty confident when seeing a question from you that you'll do all you can to make the question make sense and work with us when we post. That's way better than average so I'm happy to look forward to your next question.

PS. @Chip. Your points are well considered, but I think you may have overlooked something in the detail. ADezii's code checks the control contains a value, then goes on to check that the resultant variable strEMail contains both the characters "@" & ".".
Oct 26 '09 #18
ADezii
8,834 Expert 8TB
You do keep us somewhat busy Danica, but I admit to feeling pretty confident when seeing a question from you that you'll do all you can to make the question make sense and work with us when we post. That's way better than average so I'm happy to look forward to your next question.
I'm with you 100% on this one, NeoPa.
Oct 26 '09 #19
ChipR
1,287 Expert 1GB
I wrote that before ADezzi posted the new code, but finished after it, so it doesn't apply to the post right above it. Perhaps you could move/remove it?
Oct 27 '09 #20
NeoPa
32,556 Expert Mod 16PB
I cannot sensibly remove it Chip (sorry) after various references to it, but I have added a quote to your last post into it to make it clear for anyone who may come across it.
Oct 27 '09 #21
NeoPa
32,556 Expert Mod 16PB
A new thread was added here as a hijack. If anyone's interested in finding it, it can be found at eMail Problem in Access 2007.
May 14 '10 #22

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: dude | last post by:
hello how would i make an input mask that only makes the first letter a capitol one? i've been playing around and testing various masks, also tried the wizard, but i've had no luck. could...
2
by: Mark Lees | last post by:
I want to create an input mask for a phone number and I would like the area code to always be (801). However, I want the users to be able to edit it if necessary. Would it look like this =...
6
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would...
4
by: David W. Fenton | last post by:
I'm working on a subform where users put in 24-hour time. On their paper forms, they've been accustomed to referring to midnight as 24:00 (instead of as 0:00, which kind of makes sense from a human...
11
by: MS | last post by:
The simplest input mask for peoples names is.... >L<?????????????? But what about when you have names like MacDonald, or Mary-Anne? Anyone come up with a good "all round" "idiots" mask that...
7
by: F. Michael Miller | last post by:
I have a db with Access front end, sql back, linked tables. I need to be able to change input masks at the table level in code. Any ideas? Thanks!
16
by: Filips Benoit | last post by:
Dear all, I have a datefield that sometimes should store hours and minutes too ans use following format and inputmask. dd/mm/yyyy hh\:nn 09/09/0000\ 99:99;0;* Typing date, hour and...
12
by: panjap | last post by:
a few days a go i was kindly helped with the trouble i was having on editing lables wjhere i wanted to change access' messages to my own. Below si the qeustion i set a few days agoa , which worked...
1
by: Doug | last post by:
Hi, I created a short date field. The format is dd/mm/yyyy when displayed. The input mask is set to 99/99/00;0 (default, I didn't type anything). If I edit an existing date, say change...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.