VBA Code: Using Monarch Models

C

CM4@FL

I'm trying to use VBA code to open the Monarch software program, open the
text file I want filtered, open the monarch model and save out a new text
file filtered by by the model. The code I am using won't save the new text
file I eventually want linked into my database.

This is my understanding of the code: (see below for actual coding)

\\Chwfnp02\APPS\Monarch\program\Monarch - Opens Monarch
T:\FR\TY - US - FIS.txt - Is the file I want filterd my Monarch
T:\FR\Calc.mod - Is the model used by Monarch to filter
T:\FR\IMP_USFISTY - Is the file name I want the filtered data saved as


Function Import_Files()

DoCmd.Hourglass True
DoCmd.SetWarnings False

'Import US TY FIS
ExecCmd ("\\Chwfnp02\APPS\Monarch\program\Monarch T:\FR\TY - US -
FIS.txt T:\FR\Calc.mod T:\FR\IMP_USFISTY \t")

DoCmd.SetWarnings True
DoCmd.Hourglass False

MsgBox "All data has been successfully imported.", vbOKOnly, "Import
Complete"

End Function

Thanks in Advance
 
D

Douglas J. Steele

There's no ExecCmd command in VBA, so that's obviously a custom-written
piece of code. What does it look like?

If you were to go to the Run command, what would you have to type to
accomplish what you're trying to do?
 
C

CM4@FL

start --> Run --> monarch.exe

Douglas J. Steele said:
There's no ExecCmd command in VBA, so that's obviously a custom-written
piece of code. What does it look like?

If you were to go to the Run command, what would you have to type to
accomplish what you're trying to do?
 
C

CM4@FL

Public Sub ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ReturnValue As Integer

' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

' Wait for the shelled application to finish:
Do
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
DoEvents
Loop Until ReturnValue <> 258

ReturnValue = CloseHandle(proc.hProcess)
End Sub
 
D

Douglas J. Steele

Somehow I doubt that typing simply typing "monarch.exe" in the Run command
would filter the file T:\FR\TY - US - FIS.txt using the model T:\FR\Calc.mod
and save it as T:\FR\IMP_USFISTY

Whatever you pass as a parameter to ExecCmd has to be exactly what you'd
type in the Run command.

I suspect that you'd need something like

\\Chwfnp02\APPS\Monarch\program\Monarch "T:\FR\TY - US -FIS.txt"
"T:\FR\Calc.mod" "T:\FR\IMP_USFISTY" \t

which implies that your code needs to be

ExecCmd ("\\Chwfnp02\APPS\Monarch\program\Monarch ""T:\FR\TY - US -FIS.txt""
""T:\FR\Calc.mod"" ""T:\FR\IMP_USFISTY"" \t")
 
K

Kenny G

In this case Access is using the Monarch application to expose objects
available. The below code is under a command button in an Access 2003 DB
that I use to pull data from .doc files and then process the data and then
export the data as an Excel spreadsheet. Make sure Monarch is listed and
selected in your references under tools. It is some quick and easy
automation.

Private Sub cmdimportprocesexport_Click()


Dim openfile, openmod As Boolean
Dim ServerOn As Integer

If ServerOn = 0 Then
Set MonarchObj = CreateObject("Monarch32")

't = MonarchObj.SetLogFile("C:\Program
Files\Monarch\Projects\Census.xprj")

openfile = MonarchObj.SetReportFile("C:\temp\currentcensusdata.doc",
False)

If openfile = True Then

openmod = MonarchObj.SetModelFile("C:\Program
Files\Monarch\Models\Disch.xmod")

If openmod = True Then

MonarchObj.ExportTable ("C:\temp\currentcensusdata.xls")

End If

End If

End If

End Sub

Regards,
 
R

RD

I'm trying to use VBA code to open the Monarch software program, open the
text file I want filtered, open the monarch model and save out a new text
file filtered by by the model. The code I am using won't save the new text
file I eventually want linked into my database.

This is my understanding of the code: (see below for actual coding)

\\Chwfnp02\APPS\Monarch\program\Monarch - Opens Monarch
T:\FR\TY - US - FIS.txt - Is the file I want filterd my Monarch
T:\FR\Calc.mod - Is the model used by Monarch to filter
T:\FR\IMP_USFISTY - Is the file name I want the filtered data saved as


Function Import_Files()

DoCmd.Hourglass True
DoCmd.SetWarnings False

'Import US TY FIS
ExecCmd ("\\Chwfnp02\APPS\Monarch\program\Monarch T:\FR\TY - US -
FIS.txt T:\FR\Calc.mod T:\FR\IMP_USFISTY \t")

DoCmd.SetWarnings True
DoCmd.Hourglass False

MsgBox "All data has been successfully imported.", vbOKOnly, "Import
Complete"

End Function

Thanks in Advance


Wow! It's been years since I automated Monarch from Access. I don't
have any of my code from back then but I see that your function
doesn't contain any code to open a mod, a report or produce a text
file. It just does an import. And I'm With Douglas on the ExecCmd.
It's not in the VBA library nor the Monarch library.

Datawatch is pretty good about providing programming info (unlike
BusinessObjects). First thing, download this:
http://www.datawatch.com/downloads/Monarch_8_Programmers_Guide.pdf

I don't know which version you're working with but this should be
pretty close. Monarch has a simple object model and I don't think it
has changed much over the years.

This is the Monarch 9 Function reference:
http://www.datawatch.com/downloads/Monarch_9_Functions_Reference_Guide.pdf

Well anyway, it's a place to start. If I can dig up my old code (I'm
thinking it might have been ACC97 and Monarch V4 or 5) I'll post it.
Don't hold your breath, though. My old tech lead claimed all my work
as his own and I've had a hard time trying to find any of my original
work.

HTH,
RD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top