Testing For Presence of a Section

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In looping through the Forms collection,changing the names of several control
names in the FormHeader, I triggered an error on a form that doesn't have
one. How can I test for this?

Thank you.
Sprinks
 
Hi, Kevin.
I triggered an error on a form that doesn't have
one. How can I test for this?

Trap for error #2462 in your error handler, and then add appropriate logic
for skipping that section of the Form. Here's an example:

' * * * * Start Code * * * *

Public Function fixForm(srcFrm As Form) As Boolean

On Error GoTo ErrHandler

Dim sSectName As String
Dim nInvalidSection As Long
Dim idx As Long
Dim fSuccess As Boolean

Const MAX_SECTION As Long = 4

nInvalidSection = 0 ' Init.

For idx = 0 To MAX_SECTION
sSectName = srcFrm.Section(idx).Name ' Check whether section is
valid.


'--------------------------------------------------------------------------------
' Determine whether the current section being checked isn't in the
' source form.

'--------------------------------------------------------------------------------

If (nInvalidSection > 0) Then ' Must have
"Detail" section = 0.
nInvalidSection = 0 ' Reset.

' Do whatever.
End If
Next idx

fSuccess = True

CleanUp:

fixForm = fSuccess

Exit Function

ErrHandler:

If (Err.Number = 2462) Then ' Section # invalid.
nInvalidSection = idx
Err.Clear
Resume Next
Else
MsgBox "Error in fixForm( ) in " & Application.CurrentObjectName & _
" module." & vbCrLf & vbCrLf & "Error #" & _
Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear
fSuccess = False
GoTo CleanUp
End If

End Sub

' * * * * End Code * * * *

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. Remember that questions
answered the quickest are often from those who have a history of rewarding
the contributors who have taken the time to answer questions correctly.
 
Thanks, '69. Another arrow in the quiver.

But won't you tell me how you know my name? I don't deny it; but I'm just
curious.

Best regards.

Sprinks
 
Back
Top