jb702
asked on
Gather Information from Access.accdb Using Outlook VBA then Insert new Record
I have been learning the outlook object model and would like to do the following.
From outlook, have vba code search a table in an access db, locate certain information from various tables, using information from the current email that is selected.
What i can't figure out is how to connect to the database, which most likely will be open but sometimes would need to open it.
Can someone get me started on how to make this connection.
Thanks
From outlook, have vba code search a table in an access db, locate certain information from various tables, using information from the current email that is selected.
What i can't figure out is how to connect to the database, which most likely will be open but sometimes would need to open it.
Can someone get me started on how to make this connection.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I got this to work though...thank you
Public Sub TestingDAO()
Dim dbs As DAO.Database
Dim strDomain As String, dblCID As Double
Dim strPath As String, strDB As String
Dim strSQL As String
strDomain = "'@invitationhomes.com'"
strDB = "247Recon_Access.accdb"
strPath = "C:\Users\Jbryan\Documents\3 - Doug\247 Service DB\"
strSQL = "Select CustomerID From Customer WHERE DomainName = " & strDomain
Set dbs = DAO.OpenDatabase(strPath & strDB)
Dim rst As DAO.Recordset
Set rst = dbs.OpenRecordset(strSQL)
If Not (rst.EOF And rst.BOF) Then
dblCID = rst.Fields("CustomerID")
End If
Set rst = Nothing
End Sub
ASKER
Thank you
You declared your Recordset variable as "rst":
Dim rst As New ADODB.Recordset
But you then tried to use a variable named "Rs":
Rs.Open strSQL, con ''''' I get error here saying "Object Required"
If you change "Rs" to "rst", the ADO code would work also.
But generally speaking, it's better to use DAO when working with Access.
Dim rst As New ADODB.Recordset
But you then tried to use a variable named "Rs":
Rs.Open strSQL, con ''''' I get error here saying "Object Required"
If you change "Rs" to "rst", the ADO code would work also.
But generally speaking, it's better to use DAO when working with Access.
ASKER
Any ideas on what i'm missing.
Open in new window