I'm still not seeing anything that sticks out as to why the code crashes when you're in step-by-step debug mode. I suppose in a way that sort of makes sense because if there was something wrong with the code, then it should also not work at runtime. I made some additional adjustments to your code. Nothing significant. One part about setting the layer's visibility based on bVis, then the other is inside the For Each, when ctl.Tag = strNm, you set bVis to the ctl.Value. At that point you can actually Exit the For. (That is, assuming each layer has a unique name.)
So, I wonder if it would be possible for you to create an .mdb that is portable, you could zip up and post here. Something that doesn't necessarily use your actual data, but reproduces the problem. That way I can test it here.
Code:
Private Sub Map1_BeforeLayerDraw(ByVal index As Integer, ByVal hDC As Long)
On Error GoTo err_Before
Dim iVis As Variant
Dim strNm As String
Dim ctl As Control
strNm = Me!Map1.Layers(index).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 < 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 Then
If ctl.Tag = strNm Then
bVis = ctl.Value
Exit For
End If
Next ctl
Me!Map1.Layers(index).Visible= bVis
End If
Exit_err:
Exit Sub 'Crashes here
err_Before:
'MsgBox "'Map1_BeforeLayerDraw' - " & Err.Description
Debug.Print "'Map1_BeforeLayerDraw' - " & Err.Description
On Error Resume Next
Resume Exit_err
End Sub
Bookmarks