outlook to access via a Right Click menu?

What exactly does the message say.

Can you post exactly what you have in the access module.
 
Hi Darbid

My daughter boyfriend was round this weekend - who is a programmer. He has managed to get the project working, though there are still 2 issues remaining. I don't kniw if i should start a new post for them?

But for anyone following this link, here is the code that works along with the two issues that he didn't manage to resolve as we ran out of time.

In outlook the code is:

Private Sub emTool()

Dim accessApp As Access.Application, outlookApp As Outlook.Application
Dim outlookNamespace As Object, outlookFolder As Object, outlookMail As Object

Set outlookApp = CreateObject("Outlook.Application")
Set accessApp = CreateObject("Access.Application")
Set outlookNamespace = outlookApp.GetNamespace("MAPI")
Set outlookFolder = outlookNamespace.GetDefaultFolder(olFolderInbox)
Set outlookMail = outlookFolder.Items(7)

accessApp.OpenCurrentDatabase "C:\flicks database.accdb", False
accessApp.Run "ReceiveEmailFromOutlook", outlookMail.SenderEmailAddress

Set accessApp = Nothing
Set outlookApp = Nothing
End Sub


In the database the module code is:

Public Sub ReceiveEmailFromOutlook(ByVal emailAddress As String)

Dim database As DAO.database, record As DAO.Recordset, list As String, PromoterID As String
Dim strFilter As String

Set database = CurrentDb
Set record = database.OpenRecordset("SELECT ID FROM dbo_Promoters WHERE email = '" & emailAddress & "'", dbOpenDynaset, [dbSeeChanges])
PromoterID = record.Fields(0)

strFilter = "[PromoterID] = " & record.Fields(0)

DoCmd.ApplyFilter , strFilter
End Sub

(for anyone wanting to use this don't call the module the same name as routine! this may be obvious to many of you but it took me ages to work out that was a problem.)


So, although this code works there are two main problems:

this code only selects a particular email (7th on the list), rather than the currently highlighted email.

The second problem is that is keep opening a new copy of access rather than using the existing opened copy!

Many thanks for all your help Darbid.
 
Set outlookMail = outlookFolder.Items(7)

accessApp.OpenCurrentDatabase "C:\flicks database.accdb", False

There is the answer to your 2 questions.

Basically my code did a lot of checks to get the currently selected email.

Further it also checked to see that access was running.

It is great that you got some help, but it would have been better for him to see why the other code was causing problems. As I use the code I gave you every day it was a simple user error and not a fault of the code.
 
There is the answer to your 2 questions.

Basically my code did a lot of checks to get the currently selected email.

Further it also checked to see that access was running.

It is great that you got some help, but it would have been better for him to see why the other code was causing problems. As I use the code I gave you every day it was a simple user error and not a fault of the code.

Thanks Darbid. I have put back in a lot of your code as i appreciate that there were good reasons for them to be in there. I think when we worked on it, and had quite a few issues, that we stripped it bare so we could understand more easily what we were dealing with.

I appreciate all your input.

ian
 
Code:
Set outlookApp = CreateObject("Outlook.Application")
Set accessApp = CreateObject("Access.Application")

both these create new objects as well. if this code is in Outlook then you do not need the outlook one. The second is also the reason why access opens new again.
 
Hi Darbid

the problem is if i take out the line

Set accessApp = CreateObject("Access.Application")

i get a runtime error 7952 "you made an illegal function call" on the next line:

accessApp.Run "ReceiveEmailFromOutlook", outlookMail.SenderEmailAddress

i have tried googling but apart from corrupt ddl's i could not find an answer!

regards

ian
 
please use the code in post #19. Do your best to get it working. Then post the line and error message that you get.

The message box there is to help you know what to put in your code as the name of your database.

There is a "next" all by itself in there. Take that out.
 
i am sorry, i missed that bit of code. thanks. i am stuck a bit between to two programming styles.

there is only one more problem i have, but i will make another post as i have used up your generosity.

many thanks again for all your help. i am not a confident programmer.

ian
 

Users who are viewing this thread

Back
Top Bottom