locked
32bit --> 64 bit object not found RRS feed

  • Question

  • we have to migrate from 32 bit to 64 bit version.

    i do not have any experience with that and i heritated the database and i'm looking for help

    this is the code

     
    Function GetEmailFromNonDefaultInbox()
        Dim myOlApp As New Outlook.Application
        Dim myNameSpace As Outlook.NameSpace
        Dim myInbox As Outlook.MAPIFolder
        Dim myitems As Outlook.Items
        Dim strFilter As String
       
        Dim ns As NameSpace
        Dim Inbox As MAPIFolder
        Dim SubFolder As MAPIFolder
        Dim Item As Object
        Dim Atmt As Attachment
        Dim FileName As String
        Dim MyDocPath As String
      
        Dim wsh As Object
        Dim fs As Object
        Dim TempRst As DAO.Recordset
        Dim rst As DAO.Recordset
     
      
        Set myAccounts = myOlApp.GetNamespace("MAPI").Stores
        For i = 1 To myAccounts.Count
          
            If myAccounts.Item(i).DisplayName = "Bxxxxx" Then
                Set myInbox = myAccounts.Item(i).GetDefaultFolder(olFolderInbox)
                Exit For
            End If
        Next
        
     
     Set db = CurrentDb
        Set TempRst = CurrentDb.OpenRecordset("myfile")
        
        Set ns = GetNamespace("MAPI")
        Set Inbox = myAccounts.Item(i).GetDefaultFolder(olFolderInbox)
        Set SubFolder = Inbox.Folders("Bxxxxxsubfolder")

    ' rest of the code
    end function

    and i get this error in this line : 

    Set SubFolder = Inbox.Folders("Bxxxxxsubfolder")

    Saturday, December 7, 2019 10:25 AM

All replies

  • Defining ns without referring to myOlApp is dangerous! When automating another application such as Outlook, you must be very careful to make ALL objects in that application refer directly or indirectly to the application object. Otherwise, you risk creating orphan instances of the application that will remain in memory.

    You have two inbox variables: myInbox and Inbox

    Also: you have a lot of undeclared variables.

    Does this work better?

    Function GetEmailFromNonDefaultInbox()
        Dim myOlApp As Outlook.Application
        Dim myNameSpace As Outlook.NameSpace
        Dim myInbox As Outlook.MAPIFolder
        Dim myitems As Outlook.Items
        Dim myAccounts As Outlook.Stores
        Dim strFilter As String
        Dim ns As Outlook.NameSpace
        Dim SubFolder As Outlook.MAPIFolder
        Dim Item As Object
        Dim Atmt As Outlook.Attachment
        Dim FileName As String
        Dim MyDocPath As String
        Dim i As Long
        Dim wsh As Object
        Dim fs As Object
        Dim db As DAO.Database
        Dim TempRst As DAO.Recordset
        Dim rst As DAO.Recordset
       
        Set myOlApp = CreateObject("Outlook.Application")
        Set ns = myOlApp.GetNamespace("MAPI")
        Set myAccounts = ns.Stores
        For i = 1 To myAccounts.Count
            If myAccounts.Item(i).DisplayName = "Bxxxxx" Then
                Set myInbox = myAccounts.Item(i).GetDefaultFolder(olFolderInbox)
                Exit For
            End If
        Next i
       
        If myInbox Is Nothing Then
            MsgBox "Account not found!"
            Exit Function
        End If
       
        Set SubFolder = myInbox.Folders("Bxxxxxsubfolder")
       
        Set db = CurrentDb
        Set TempRst = db.OpenRecordset("myfile")
       
    ' rest of the code
    End Function


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by tekoko10 Monday, December 9, 2019 9:39 AM
    • Unmarked as answer by tekoko10 Tuesday, December 17, 2019 7:14 AM
    Saturday, December 7, 2019 12:09 PM
  • Re undeclared variables:

    The OP probably does not have "Option Explicit" at the top of every module, and does not have VBA window > Tools > Options > Require variable declarations

    checked, against best practices. Please add it now; then choose Debug > Compile and fix the errors that may occur.

    I also cringe when I see a mix of early binding and late binding, thinking the OP may not know the difference and has not studied this important topic.


    -Tom. Microsoft Access MVP

    Saturday, December 7, 2019 7:02 PM
  • Look at the post "32Bit to 64BIT change Need Help" posted 12/8/2019 in MSDN Forums..Either way,to change/upgrade the pc OS,one can/could boot pc to BIOS,boot priority,install the Windows OS installation cd,set to boot to cd,1st boot priority,HD 2nd,save & exit BIOS.GetMail notice from youre post makes has no value in a new Win 10 OS,also Visual Basic is retired to Visual Studio.
    Sunday, December 8, 2019 11:46 PM
  • Hello Hans,

    in this line

    Set SubFolder = myInbox.Folders("Bxxxxxsubfolder")

    i get now this error 

    Tuesday, December 17, 2019 7:27 AM
  • It looks like myInbox doesn't contain a subfolder named Bxxxxxsubfolder...

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Tuesday, December 17, 2019 12:38 PM
  • There is a cool product OutlookSpy that allows you to inspect everything about Outlook. 

    -Tom. Microsoft Access MVP

    Tuesday, December 17, 2019 1:14 PM
  • I do not see what is wrong

    Tuesday, January 7, 2020 7:57 AM
  • That's why I recommended the tool that I did: it would allow you to traverse everything and learn more.

    In lieu of that, you could write code to iterate over the various collections and debug.print their items and properties.


    -Tom. Microsoft Access MVP

    Tuesday, January 7, 2020 1:47 PM
  • Hi tekoko10,

    Have you tried to add the References for OutLook? It's  something like "Microsoft OutLook XX.X Object Library". But I'm not certain about 32bit and 64bit references.

    You might want to re-code it to Late-Binding instead.

    "Dim SubFolder As MAPIFolder" >>> not sure why you did not get error here. Missing "Option Explicit"?

    "Dim SubFolder As Outlook.MAPIFolder"  >>> should be correct for early binding

    "Dim SubFolder As Object" >>>  for Late Binding then set the object "SubFolder" for outlook.

    HTH

    Wednesday, January 8, 2020 3:12 AM
  • Thanks Tom,

    But the database is on an online server and i can not install tools there. (i tried it)

    Wednesday, January 8, 2020 7:14 AM
  • option explicit is ok , this is my code so far

    Option Compare Database
    Option Explicit

    Function GetEmailFromNonDefaultInbox()
        Dim myOlApp As Outlook.Application
        Dim myNameSpace As Outlook.NameSpace
        Dim myInbox As Outlook.MAPIFolder
        Dim myitems As Outlook.Items
        Dim myAccounts As Outlook.Stores
        Dim strFilter As String
        Dim ns As Outlook.NameSpace
        Dim SubFolder As Outlook.MAPIFolder
     
        Dim Item As Object
        Dim Atmt As Outlook.Attachment
        Dim FileName As String
        Dim MyDocPath As String
        Dim i As Long
        Dim wsh As Object
        Dim fs As Object
        Dim db As DAO.Database
        Dim TempRst As DAO.Recordset
        Dim rst As DAO.Recordset
        Dim aantal As Long
        Dim aantalmails As Long
       
        Set myOlApp = CreateObject("Outlook.Application")
        Set ns = myOlApp.GetNamespace("MAPI")
        Set myAccounts = ns.Stores
        For i = 1 To myAccounts.Count
      
            If myAccounts.Item(i).DisplayName = "Bestel" Then
            
                Set myInbox = myAccounts.Item(i).GetDefaultFolder(olFolderInbox)
                Exit For
            End If
        Next i
       
        If myInbox Is Nothing Then
            MsgBox "Account not found!"
            Exit Function
        End If
      
       
        
        Set SubFolder = myInbox.Folders("bestellingen")

    Wednesday, January 8, 2020 10:48 AM
  • Then it's a good thing I answered with two sentences.

    -Tom. Microsoft Access MVP

    Wednesday, January 8, 2020 1:27 PM
  • This is incorrect.

    There is nothing you can do with late binding that you cannot also do with early binding.

    The suggested declaration makes no difference assuming there is no other reference that implements the MAPIFolder class, a reasonable assumption.

    That declaration is also not affected by Option Explicit


    -Tom. Microsoft Access MVP

    Wednesday, January 8, 2020 1:37 PM