CorkyShunk

LayerBeforeDraw Event Crahses Application

Discussion created by CorkyShunk on Mar 23, 2012
Latest reply on Sep 20, 2012 by jbarry-esristaff
Using MOLT 2.0
I have the Map_BeforeLayerDraw sub running code to determine if a layer should be visible per the Map extent. I wrote this 2+ years ago and it has worked fine. Now I have a user that crashes the app. It appeared to be occurring during the LayerBeforeDraw. When I run that app on all office PCs it functions fine. When I step through the sub it causes the app to crash on the 'Exit Sub' or 'End Sub' ine execution? I never stepped through this sub before. I wrote it and it worked fine.
App is written in MS Access 97, 2002, 2003, 2007, 2010 and has always functioned fine.

Closes / Crashes Access at the 'Exit sub' or 'End Sub' line when stepping through the sub in A97, 2003 or 2007 (haven't tried in 2010)

Tried to debug with Visual Sudio and it gave me this:
'Unhandled exception at 0x2832d7bb in MSACCESS.EXE: 0xC0000005: Access violation reading location 0x00000004.'


Private Sub Map1_BeforeLayerDraw(ByVal Idex As Integer, ByVal hDC As Long)
On Error GoTo err_Before

        Dim iVis As Integer
        Dim strNm As String
        Dim ctl As Control
        Dim ILayer As Object
       
        Set ILayer = Me!Map1.Layers(Idex)
        strNm = ILayer.Name
        iVis = Val(fLayerInfo(strNm, 9))
       
            If iVis > 1 Then
            '' Depending on the extent & 'MaxVis' setting determines if layer is drawn
            If Me!Map1.Extent.Width < Me!Map1.FullExtent.Width / iVis Then
                '' check if the layer is to be visible
                Dim bVis As Boolean           
                For Each ctl In Forms!frmGISMap!sfrmLayers.Form.Controls
                    If ctl.ControlType = acCheckBox And ctl.Tag = strNm Then
                        bVis = ctl.Value
                        Exit For
                    End If
                Next ctl
                If bVis Then ILayer.Visible = True
            Else
                ILayer.Visible = False
            End If
      
        DoEvents
   
Exit_err:
    If Not ILayer Is Nothing Then Set ILayer = Nothing
    Exit Sub '' CRASH OCCURS WHEN THE 'Exit Sub' FIRES, IF THE ERROR HANDLER IS COMMENTED OUT CRASHES ON 'End Sub'
err_Before:
    MsgBox "'Map1_BeforeLayerDraw' - " & Err.Description
    'Debug.Print "'Map1_BeforeLayerDraw' - " & Err.Description
    On Error Resume Next
    Resume Exit_err

End Sub


Cork Shunk
CS-Graphx

Outcomes