outlook to access: follow up

What I mean is, if I am in the VbaProject.OTM vb editor I have no " Project" button
Instructions
Open the Project button on the Visual Basic toolbar. Find the project you want to test.
from ehow.com

This does nothing
To single step through this macro we can either go into the VBE, switch to the module containing the macro and then click on the 'Single Step' button from the Debug toolbar or the Debug menu,
from techbookreport.com

Neither F8 or Cntrl+F8 do anything. I am setting up another machine to see if my software has gone wrong but this is just putting even more time into something taht is probably simple for someone of your ability.

Maybe I have some form of reference missing, maybe the OTM project is vba not vb, maybe I just don't really know what I am doing.

Whatever the case is I am not a VB developer and I am trying to catch with things I need to know as I am trying to implement them.
 
Sorry, I didn't finish answering your question...

VbaProject.OTM=
Code:
If objDBase.Name = "C:\Orders.mdb" Then 
appAccess.Run "fromOutlook", Item

Module named fromOutlook (Object = (General))(Procedure = fromOutlook)
Code:
Public Sub fromOutlook(ByRef olMail As Outlook.MailItem)
MsgBox "4"
End Sub
 
Darbid, are you still here?
 
Darbid, are you still here?
Yep. I have read your posts. You need to learn about the VBE (which ever version you have. You need to put a break point in there and then with F8 step through your code. You need to understand what is being called and what is getting values or not.

If we do not do that this is going to take a long time. And you will learn nothing.

eg

http://www.cpearson.com/excel/Debug.htm
 
I have set up a Windows7 box running Office2007. I have copied & pasted your exact code into both Outlook and Access.

When I send an email to that mail account nothing happens, no MsgBoxes, no Item.Class confirmations, nothing.

Although I can set breakpoints on individual lines (the same as could do on the original machine) neither F8, ctrl+F8 or Menu driven commands do anything.

Can anyone help please?
 
I think we are going backwards here now.

You have already got this to work. Now you have a problem. If you have used exactly the same code that did once work and you confirmed that it once worked then i am sorry but it looks like you have done something different. I do not think that with this example W7 or Office 2007 is different. Although I have not tested it.

You now need to debug. Is the Application at start up fireing? is the folder object being set? What else is different? What code have you copied?
 
Darbid,

I understood what you meant, I know what breakpoints are, and I know what you would like me to do. The problem is...

For e.g. if I highlight
Code:
Private Sub Application_Quit()
MsgBox "2"
    Set olInbox = Nothing
End Sub
then I can debug it in an immediate window (i.e. I get the little yellow arrow in the left margin) and I can step through it.

However, if I highlight
Code:
Private Sub olInbox_ItemAdd(ByVal Item As Object)
On Error GoTo Err_olInbox_ItemAdd

    Dim appAccess As Object 'late binding of the MSAccess object
    Dim objDBase As Object 'late binding
    
    MsgBox "My Item Class is " & Item.Class
    
 
If Item.Class = 43 Then
    Set appAccess = GetObject(, "Access.Application") 'get a database
    
    If TypeName(appAccess) = "Nothing" Then MsgBox "Failed to get Access"
    
    Set objDBase = appAccess.CurrentDb
    
    If TypeName(objDBase) = "Nothing" Then MsgBox "Failed to get current DB"
        
    MsgBox "objDBase.Name is " & objDBase.Name

If objDBase.Name = "C:\Console\ConsoleIIIv2.7.6.mdb" Then 'here I check the name of the current database - incase there is more than one open
   appAccess.Run "fromOutlook", Item
End If

Set appAccess = Nothing
Set objDBase = Nothing

End If

 
Exit_olInbox_ItemAdd:

Exit Sub

Err_olInbox_ItemAdd:
    MsgBox Err.Description & " olInbox_ItemAdd", vbCritical, "Error"
    Resume Exit_olInbox_ItemAdd
    
End Sub
I can set breakpoints but I can't step through the code. I don't get the yellow arrow and neither F8 or ctrl+F8 do anything. The same applies to the Access module.

Would you like me to try and setup debug.print lines & would that help?
 
put a msgbox in the application start up and make sure it is fireing as well as check for the name of the folder that is set.
 
I think we are going backwards here now....

The win7/office2007 was a testbox to see if there was something wrong with my vb editor on my other box.

If I open outlook I get the MsgBox "3" to confirm the application startup, and
if I close Outlook I get the MsgBox "2" to confirm application quit. I therefore know that the two subs are working.

The ItemClass MsgBox "43" comes up and then the database name MsgBox comes up when new mail is received. I then get the error " databasename can't find the procedure 'fromOutlook.'olInbox.ItemAdd
 
I think I know where the problem is, I just don't know what to do about it.

If I do this
Code:
If objDBase.Name = "C:\Orders.mdb" Then Msgbox "5"
' appAccess.Run "fromOutlook", Item
, then I get MsgBox "5"

But, if I do this
Code:
If objDBase.Name = "C:\Orders.mdb" Then 
   appAccess.Run "fromOutlook", Item
MsgBox "5"
, then I get nothing.

I think the line appAccess.Run "fromOutlook", Item is getting stuck somewhere but I can't debug it.
 
You have changed database names. Does the new database have a module with a public sub with exactly the same name?
 
There has only ever been a database called Console.....mdb. I was just using the name "orders" because it is quicker to type.
Yes, he module is in th database.
 
I think I know where the problem is, I just don't know what to do about it.

If I do this
Code:
If objDBase.Name = "C:\Orders.mdb" Then Msgbox "5"
' appAccess.Run "fromOutlook", Item
, then I get MsgBox "5"

But, if I do this
Code:
If objDBase.Name = "C:\Orders.mdb" Then 
   appAccess.Run "fromOutlook", Item
MsgBox "5"
, then I get nothing.

I think the line appAccess.Run "fromOutlook", Item is getting stuck somewhere but I can't debug it.

This tells me you do not know how to debug nor do you know how to use the break point and to step through your code.

I have one more post in me and then I think I will give up if we cannot make some forward progress here.
 
1. cut and copy the following code into Outlook.
2. To do this with Outlook 2007 please go to Tools>Macro> Visual Basic Editor.
3. Then go to ThisOutlooksession.
4. Paste this code.
Code:
Public WithEvents olInbox As Outlook.Items
Private Sub olInbox_ItemAdd(ByVal Item As Object)
On Error GoTo Err_olInbox_ItemAdd

    Dim appAccess As Object 'late binding of the MSAccess object
    Dim objDBase As Object 'late binding
 

    Set appAccess = GetObject(, "Access.Application") 'get a database
    Set objDBase = appAccess.CurrentDb
    
    Debug.Print objDBase.Name


   appAccess.Run "fromOutlook", Item


Set appAccess = Nothing
Set objDBase = Nothing

End If

 
Exit_olInbox_ItemAdd:

Exit Sub

Err_olInbox_ItemAdd:
    MsgBox Err.Description & " olInbox_ItemAdd", vbCritical, "Error"
    Resume Exit_olInbox_ItemAdd
    
End Sub

Private Sub Application_Quit()
MsgBox "Outlook Closing"
    Set olInbox = Nothing
End Sub

Private Sub Application_Startup()
MsgBox "Outlook Opening"
Set olInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub
5. Now save it and close outlook properly. Make sure it is also NOT a process running in Task manager.
6. On closing you will get the message Outlook Closing
7. Once you know outlook is closed.
8. Open 1 access database file. ONLY ONE.
9. In there make a new module and put the following code

Code:
Public Sub fromOutlook(ByRef mymail As Outlook.MailItem)

MsgBox mymail.Subject


End Sub
10. add a reference to Microsoft Outlook in your Access.
11. Save this and leave access sitting there.
12. Open Outlook, you will receive the Outlook message that it is starting.
13. Go into theVBE editor and put a break point. You do this by clicking on the side frame like in my added pic below. See the dot? That is where you click.
14 Now send your self an email WITH a subject.
15. The VBeditor will spring open and it will stop on the line you have broken at.
16. now step through the code and see that each line works.

I have just tested this on Outlook 2007 / Access 2003 and it works. If you cannot get it to work that is it for me I do not know what your problem is.
 

Attachments

  • New Picture (1).jpg
    New Picture (1).jpg
    16.1 KB · Views: 105
ok, so here is what I am doing.

In the VB editor window I have the code loaded. I then do exactly what every "Debug vb" site (including the link you sent) says.

You can step through code line by line by pressing the F8 key to start the procedure in which the cursor is, or when VBA is paused at a break point. Pressing F8 causes VBA to execute each line one at a time, highlighting the next line of code in yellow.
Nothing happens when I press F8, nothing turns yellow.

If I am doing something wrong then teach me what it is, don't keep telling me I don't know what I'm doing. I told you that back on page 1 of this thread.
 
I think we have moved forward..

Doing exactly what you have told me to, and then reloading the old code I have noticed 3 things:-

1. You have a module loaded in your Outlook project. Mine is in Access.
2. Hovering the cursor over the word Item in
Code:
 appAccess.Run "fromOutlook", Item
reveals Item = "17"
3. If I choose "Definition" from a right-click context menu the word Item in
Code:
Private Sub olInbox_ItemAdd(ByVal Item As Object)
is highlighted.

BTW, I set my Outlook project to look like yours in your attached jpg, your breakpoint is set at
Code:
If Item.Class = 43 Then
and your immediate window is displaying "C:\something. If I do the same thing my immediate window is blank.

If I may ask a question, the references I have in vbaProject.OTM are:
Visual Basic for Applications
Microsoft Outlook 12.0 Object Library
OLE Automation
Microsoft Office 12.0 Object Library
Microsoft Office 12.0 Access Database engine Object Library
Microsoft ActiveX Data Objects 2.8 Objects Library
Microsoft ActiveX Data Objects RecordSet 2.8 Objects Library
Microsoft Access 12.0 Object Library

In Access my references are:
Microsoft Outlook 12.0 Object Library
Microsoft Outlook 12.0 Object Library
OLE Automation
Microsoft DAO 3.6 Object Library
Microsoft ActiveX Data Objects 2.1 Objects Library
Microsoft Terminal Services Active Client 1.0 Type library

excluding the TS client, can you see anything missing?
Microsoft Access 12.0 Object Library
 
BTW, I set my Outlook project to look like yours in your attached jpg, your breakpoint is set at
Code:
If Item.Class = 43 Then
buddy my code above does not have this line.

I have a module in Outlook cause I do have my own code as well.

Please follow the intructions.
 
"fromOutlook", Item[/code] reveals Item = "17"
3. If I choose "Definition" from a right-click context menu the word Item in
Code:
[/quote]
  So find out what item class 17 is.

Then post back here.

Either it is not really 17 or you are doing something majorly wrong here.
 
My friend (and I could hopefully call you "my friend" because I have said more to you in the last 3 days than I have said to my wife :)).

It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!! It works !!!

The difference...I didn't give the Access module a name, I left it as Module 1 instead of calling it fromOutlook. The code was erroring at the Access module entry point, not in the Outlook module.(I think)
 
Last edited:
Darbid,

Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you.
 

Users who are viewing this thread

Back
Top Bottom