Code --
Bearing in mind this is very specific to our set up..
For instance the location of the executable will be different for your location and the reference to the necessary fields will be completely different as well. You will also need to substitute in the name of the theme that has polygons with the necessary "Key field". In that effect ArcView is very much acting as a repository of a separate table with a one to one relationship with the ID field in Access...
Also bear in mind that this links an Access 2003 application to ArcView 3.1 in Windows 2000 if you are in Windows XP you need to use ArcView 3.3 and I think add a patch to 3.3 to the listed Avenue code should then work.
Also note that the Avenue script may need to be re-written in VB.net depending on whether ArcGIS supports Avenue or not.
Finally this is not a Geodatabase solution (see also Kevin S post for explanation) - it is linking a polygon through to a reference field in a database...Personally though I think it has several advantages over ArcSDE option - it separates the digital geometry from the attributes (so what if you can hold grid references information in a database ) it's hardly a burning desire to look at 40 million 6 digit numbers, shades of Matrix or what) - it means you don't need to buy ArcSDE (expensive) - and anyone can edit the polygons (saves you on the purchase of ArcEditor).
Note ArcGIS will link direct to Access without ArcSDE as a "Personal Geodatabase" option. The implication is that it won't work with more than one user over a network. This is a true geodatabase as mentioned by some of the other contributors above. We've set such a personal geodatabase up and so far works great. We are going to try and get multiple users to link to this geodatabase and just see what happens...!!!
My thanks to a colleague of mine John Thain who wrote this code and has kindly agreed to it's publication...
Code behind the access button : -
Private Sub CGetMap81_Click()
Dim sScript As String, sEasting As String, sNorthing As String, sGridrefs As String, sID As String
Dim sCommand As String, sAVTheme As String
sAVTheme = "GlobalHousing"
Const NO_DATA_ERR = 94
Const AV_NOT_LAUNCHED = -2147352571
On Error GoTo StartArcView
'-------------------------------------------
'use values from current record using DAO
Dim rst As DAO.Recordset
Set rst = Me.Recordset
sEasting = Str(Me!EAST)
sNorthing = Str(Me!NORTH)
sID = Str(Me.ID)
sGridrefs = sEasting & "," & sNorthing
'-------------------------------------------
sScript = "WLCEd.ZoomToSite"
sCommand = "av.RUN(" & Chr(34) & sScript & Chr(34) & ",{" & Chr(34) _
& sGridrefs & "," & sID & "," & sAVTheme & Chr(34) & "})"
ContinueAfterLaunchingArcView:
lngChan1 = DDEInitiate("ArcView", "System")
DDEExecute lngChan1, sCommand
Application.DDETerminate lngChan1
Exit Sub
StartArcView:
If Err = NO_DATA_ERR Then
MsgBox "Can't locate housing site, no grid refs.!!"
Exit Sub
ElseIf AV_NOT_LAUNCHED Then
Shell "c:\ESRI\AV_GIS30\ArcView\Bin32\ArcView.exe E:\arcview.dat\projects\mbprojects\p079.apr", vbNormalFocus
Err = 0
Resume ContinueAfterLaunchingArcView
End If
End Sub
And the Avenue Script : -
'*******************************************************************
'* Name: WLCEd.ZoomToSite *
'* Text: zoomsite.ave *
'* Author: John H Thain *
'* *
'* Headline: Zooms to extent of housing site *
'* *
'* Self: 0 - the X coordinate (Easting) *
'* 1 - the Y coordinate (Northing) *
'* Returns: Nothing *
'* *
'* Description: Zooms to extent of site + 1000 *
'* NOTE - this script is designed to be run from *
'* Microsoft Access database *
'* It is not assumed that a View is the active *
'* *
'* History: Wed 16 Oct 2002 - Original Coding *
'*******************************************************************
args = Self.Get(0).AsTokens(",")
xCoord = args.Get(0).AsNumber 'not required but passed from Access
yCoord = args.Get(1).AsNumber 'not required but passed from Access
siteID = args.Get(2).AsNumber 'site reference
housingTheme = args.Get(3).AsString 'GlobalOpenSpace
'msgbox.Info (siteID++housingTheme.AsString, "Info")
'Restore the ArcView window
av.Restore
'thePoint = Point.Make(xCoord,yCoord)
viewList = {}
for each d in av.GetProject.GetDocs
if (d.Is(View)) then
viewList.Add(d)
end
end
for each theView in viewList
for each t in theView.GetThemes
if (t.AsString = housingTheme) then
t.SetVisible(TRUE)
theHousingFTab = t.GetFtab
theBitmap = theHousingFTab.GetSelection
' build a query string
theQuery = "([Id] = "+siteID.AsString+")"
'msgbox.info (theQuery.AsString, "Info")
theHousingFTab.Query(theQuery, theBitmap, #VTAB_SELTYPE_NEW)
theHousingFTab.UpdateSelection
r = Rect.MakeEmpty
if (t.CanSelect) then
r = r.UnionWith(t.GetSelectedExtent)
end
if (r.IsEmpty) then
return nil
elseif ( r.ReturnSize = (0@0) ) then
theView.GetDisplay.PanTo(r.ReturnOrigin)
else
theView.GetDisplay.SetExtent(r.Scale(1.1))
'-----------------------------------------
d = theView.GetDisplay
s = theView.ReturnScale
'msgbox.info (s.asString, "Info")
'-----------------------------------------
'if (s < 1000) then
d.ZoomToScale(s + 1000) 'Mark scale of extent of site + 1000
'end
end
end
end
theView.Invalidate
end