Opening Proviewer from MS Access

115 views
Skip to first unread message

GrantH

unread,
Dec 11, 2008, 8:44:22 AM12/11/08
to MapInfo-L
I create the workspace file below using VBA, when opened it starts the
program associated with .WOR files (MapInfo) and centers the map. In
order to reduce the amount of work required in code the temp workspace
references another, however it appears that Proviewer can't handle
this. Is there a way around this at all?

This is the full workspace file contents ("temp.wor"):

!Workspace
!Version 650
!Charset WindowsLatin1
Run Application "C:\test.wor"
Set map
Center (519605, 196788)

The 4th line causes the problem - Proviewer reports a "Invalid clause
[application] in [run] command".
I know Proviewer can't run MBX's but I thought it would allow a
workspace (it's not feasible to create the entire test.wor workspace
in code!).

Peter Horsbøll Møller

unread,
Dec 11, 2008, 1:59:57 PM12/11/08
to mapi...@googlegroups.com
Grant,
 
Run Application is used for opening workspaces and for running MapBasic applications.
I guess that might explain why MapInfo ProViewer can't execute a workspace thru code.
 
You could have the default workspace stored as a file, copy the file and just add the extra two lines to the copy, and then open that workspace in ProViewer.
Peter Horsbøll Møller
2008/12/11 GrantH <gdhe...@gmail.com>

Mark Dvorscak

unread,
Dec 11, 2008, 5:04:36 PM12/11/08
to MapInfo-L
Grant,

Peter has the right suggestion. We use ProViewer this way. I create
the workspace in MIPro as a template with variables for the Set Map
Center(x,y). Data to replace the variables comes from the VB script
and is written to a copy of the template workspace which then launches
in ProViewer. Non-GIS users in the office then have a map centered on
their chosen coordinates with all associated data available for them
to view. It works well.
Mark Dvorscak

Adrian Gray

unread,
Dec 12, 2008, 5:20:30 AM12/12/08
to mapi...@googlegroups.com
GrantH,

Your generated workspace isn't loading any tables or configuring the map so
why not leave out the Run Application command and call two separate
workspaces? Windows should load ProViewer on the first call to a workspace
file. Then the currently running ProViewer will run the second workspace
request and the set map centre.

If you are using the shell command from VBA in Access I think you can also
specify two workspace files in the command e.g. shell....proviewer.exe
"test.wor" "test2.wor"

Failing that Peter's suggestion of copying and inserting you commands at the
end is a good solution. Although, if you were copying you may as well read
it and replace the set map centre command as you output to a new workspace
file.

Hope this helps

Regards

Adrian Gray
Viewshed Limited
www.viewshed.co.uk
t: 01392 861946 f: 01392 861947
Orchard House Church Road Silverton Exeter EX5 4PD
registered in England and Wales 876 6186 72 VAT# 5661115

Business data from your vantage point

Got an LLPG? - try FuzzyLLPG for FREE. It builds a layer of your addresses,
has a fuzzy search engine and can merge tables together using the UPRN.
Download it from our website!

GrantH

unread,
Dec 12, 2008, 11:43:24 AM12/12/08
to MapInfo-L
Thanks, I got it working using Peter's method, code is below for
anyone else who is searching for a way to do this (MS Access VBA).
The workspace selected is copied to the local drive and the two lines
"Set Map" and "Center (x,y)" are written to the end of it (X and Y
come from my form).
Workspace file is then opened in Proviewer and it works perfectly!
Unfortunately it opens a new version of Proviewer each time, but I
will work on that.


Code snippet below:
---------------------------
'copy workspace file to c:\, will overwrite it if exists
Dim fs As Object
Dim oldPath, newPath, strWORFILE As String
oldPath = " c:\temp " 'Folder file is located in
newPath = "C:\temp\temp" 'Folder to copy file to

strWORFILE = "Proviewer_Base.WOR" 'name of file to copy

Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFile oldPath & "\" & strWORFILE, newPath & "\" & strWORFILE
'copy file to new path location
Set fs = Nothing

'define new file
strFileName = newPath & "\" & strWORFILE

'edit file
Open strFileName For Append As #1

'write to file contents

'sets map to center from Easting/Northing for address selected on form
strFile = "Set map"
Print #1, strFile
strFile = "Center (" & strX & ", " & strY & ")"
Print #1, strFile

Close #1

'Open temporary workspace in Proviewer/MapInfo

PVPath = "C:\Program Files\MapInfo\Proviewer\Mapinfor.exe"
retval = Shell(PVPath & " " & strFileName, vbNormalFocus)
If retval = 0 Then
MsgBox "An Error has occurred opening Proviewer", vbOKOnly,
"Proviewer Error!"
Exit Sub
End If
---------------------

Might not be the most elegant but it works.

Cheers
Grant
Reply all
Reply to author
Forward
0 new messages