Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Tag Cloud
access acer asus bios bsod crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop mac malware memory monitor motherboard network operating system printer problem ram registry router security slow software sound svchost.exe trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
Outlook VBA to fetch data from Access table

Reply  
Thread Tools
jsp49's Avatar
Junior Member with 1 posts.
 
Join Date: May 2009
13-May-2009, 06:21 PM #1
Outlook VBA to fetch data from Access table
Hi,

Within Outlook, I am looking to add a Toolbar button that calls a vba procedure that does the following:
-Prompt user for a code
-Find the code in fldCode in tblLookup in an Access database
-Fill in the To, Subject, Body, etc in a new mail message based on contents from the tblLookup

Any ideas. I have been scratching my head in defeat for quite a long time - any help would be truly appreciated!!
terabytecomputer's Avatar
Member with 104 posts.
 
Join Date: Apr 2009
Experience: Hooked since my TI-99/4A
20-May-2009, 03:40 PM #2
This should get you started. Make sure you add in the 'Microsoft ActiveX Data Objects 2.8 Library' (I added 2.8, other versions may work) by opening Outlook Visual Basic and going to 'Tools', 'References'.

Create a Macro in Outlook and code it to connect to your database something like this:

Sub GetMyData()
Dim myCn As New ADODB.Connection
Dim myCmd As New ADODB.Command
Dim myRs As New ADODB.Recordset

Set myItem = Outlook.CreateItem(olMailItem)

myCn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=databasename.mdb;" & _
"DefaultDir=databaselocation (c:\whatever\whatever);"

Set myRs = myCn.Execute("Select * from tablename")

'Replace field names in my example below to match your database fields
myItem.To = myRs.Fields("EmailAddress")
myItem.Subject = myRs.Fields("Subject")
myItem.Send

'Be sure to close the recordset and connection when you're done
Set myRs = Nothing
Set myCn = Nothing

End Sub

After you create that macro, you can add it as a button to a toolbar. In Outlook, select 'Tools', 'Customize', 'Commands' tab, 'Macros'. Drag your macro to the toolbar.

Hope this helps.
__________________
If you're not living on the edge, you're taking up too much space!

Last edited by terabytecomputer; 20-May-2009 at 03:50 PM..
Reply

Tags
access, default, fetch, outlook, vba

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:33 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.