Problem Using "MonarchObj.OpenDatabase" in COM Automation

Al_22614
Al_22614 Altair Community Member
edited April 2021 in Community Q&A

I am suddenly going blank remembering how to use the MonarchObj.OpenDatabase function in a VBA code using COM automation in Monarch.  Below is an extract of the code from the Module in Excel.  The source file is a Excel .xlsx file and the Tab (Table Name) is "HDR_META_NO".  Could some provide help or sample code using this function.  A little help will get me back on track...

Set MonarchObj = GetObject("", "Monarch32")
'
If MonarchObj Is Nothing Then
Set MonarchObj = GetObject("Monarch32")
End If
'
OpenFile = MonarchObj.OpenDatabase(FLDR & EDI_FILE, "", "HDR_META_NO")
'
If OpenFile = False Then
MsgBox "There are no Qualifying Files Remaining in the EDI Master Folder"
GoTo GoAway
Else
OpenMod = MonarchObj.SetModelfile(ModelFolder & "EDI_FINAL_LOAD.dmod")
MonarchObj.CurrentSummary = BSSUM4
EXPFILE = MonarchObj.JETEXPORTSUMMARY(SumFolder2 & SummaryFile2, BSSUM4, 2)
'

image

Many thanks.... Much appreciated

Al

Answers

  • CPorthouse
    CPorthouse
    Altair Employee
    edited April 2021

    I just looked at the MonarchAutomationObject and noticed the method signature for OpenDatabase is as follows:

    bool OpenDatabase(string connect, string password, string tableName, string modelName)     Member of Datawatch.Desktop.Automation.IMonarchAutomationObject 

    If I am looking at the same object, you now set the model in OpenDatabase rather than a separate call to SetModelFile.

  • Al_22614
    Al_22614 Altair Community Member
    edited April 2021

    Excellent!!  Got it!  All is working perfect now!!

    SumFolder2 = FLDR
    Const ModelFolder = "C:\Users\user2\ThorTestFolder\Models\"
    SummaryFile2 = YrMon & "_EDI_Detail_ReportX.xlsx"
    MODFILE = ModelFolder & "EDI_FINAL_LOAD.dmod"
    '
    '=================================================
    '
    Set MonarchObj = GetObject("", "Monarch32")
    '
    If MonarchObj Is Nothing Then
    Set MonarchObj = GetObject("Monarch32")
    End If
    '
    OpenFile = MonarchObj.OpenDatabase(FLDR & EDI_FILE, "", "HDR_META_NO", MODFILE)
    '
    If OpenFile = False Then
    MsgBox "There are no Qualifying Files Remaining in the EDI Master Folder"
    GoTo GoAway

    '
    Else
    MonarchObj.CurrentSummary = BSSUM4
    EXPFILE = MonarchObj.JETEXPORTSUMMARY(SumFolder2 & SummaryFile2, BSSUM4, 2)
    '
    End If

    Many Thanks!!!

    Al