Announcement

Collapse
No announcement yet.

Outlook AddStore problems

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Outlook AddStore problems

    I have the following (working) VBS function that adds an existing PST file to the default Outlook profile...

    Code:
     
    SUB AttachPST(strPSTPath)
     DIM objOutlookApp, objNameSpace
     ' Instantiate Outlook
     SET objOutlookApp = CreateObject("Outlook.Application")
     ' Get the MAPI Namespace
     SET objNameSpace = objOutlookApp.GetNameSpace("MAPI")
     ' Add the PST
     objNameSpace.AddStore strPSTPath
     ' Cleanup
     SET objNameSpace = NOTHING
     SET objOutlookApp = NOTHING
    END SUB
    I have attempted to recreate this natively in PowerBASIC using this code...

    Code:
     
    FUNCTION AttachPST( strPSTPath AS STRING ) AS LONG
     LOCAL objOutlookApp AS Int__Application
     LOCAL objNameSpace AS Int__NameSpace
     FUNCTION = %FALSE
     ' does the PST exist?
     IF ISFILE( strPSTPath ) THEN
      ' Instantiate Outlook
      SET objOutlookApp = NEWCOM $PROGID_Outlook_Application
      ' Do we have the Outlook object?
      IF ISOBJECT( objOutlookApp ) THEN
       ' Get the MAPI namespace
       objNameSpace = objOutlookApp.GetNamespace( UCODE$( "MAPI" ))
       ' Do we have a namespace?
       IF ISOBJECT( objNameSpace ) THEN
        ' Add the PST to the list of stores
        objNameSpace.AddStore UCODE$( strPSTPath )
        'Clean up
        objNameSpace = NOTHING
        FUNCTION = %TRUE
       END IF
       'Clean up
       objOutlookApp = NOTHING
      END IF
     END IF
    END FUNCTION
    Whenever I run the PowerBASIC version it doesn't add the existing PST, it creates a new one. Can anyone see something obvious that I might be missing?
    <b>George W. Bleck</b>
    <img src='http://www.blecktech.com/myemail.gif'>

  • #2
    This is wrong:

    Code:
    objNameSpace.AddStore UCODE$( strPSTPath )
    Must be:

    Code:
    objNameSpace.AddStore strPSTPath
    The parameter is a variant, not a string, therefore it is converted automatically to unicode.
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      JACKPOT!

      I've been staring at that code for hours. I got too close to it and just didn't see the simple mistake I knew it was.

      Thanks José I've been pulling my hair out on that one.

      And the working code is...

      Code:
       
      FUNCTION AttachPST( strPSTPath AS STRING ) AS LONG
       LOCAL objOutlookApp AS Int__Application
       LOCAL objNameSpace AS Int__NameSpace
       FUNCTION = %FALSE
       ' does the PST exist?
       IF ISFILE( strPSTPath ) THEN
        ' Instantiate Outlook
        SET objOutlookApp = NEWCOM $PROGID_Outlook_Application
        ' Do we have the Outlook object?
        IF ISOBJECT( objOutlookApp ) THEN
         ' Get the MAPI namespace
         objNameSpace = objOutlookApp.GetNamespace( UCODE$( "MAPI" ))
         ' Do we have a namespace?
         IF ISOBJECT( objNameSpace ) THEN
          ' Add the PST to the list of stores
          objNameSpace.AddStore strPSTPath
          'Clean up
          objNameSpace = NOTHING
          FUNCTION = %TRUE
         END IF
         'Clean up
         objOutlookApp = NOTHING
        END IF
       END IF
      END FUNCTION
      <b>George W. Bleck</b>
      <img src='http://www.blecktech.com/myemail.gif'>

      Comment

      Working...
      X