I have a code that opens up each module connected to all forms.
The code looks something like this:
Dim strTemp As String, mdl As Module
Dim docs As Documents, doc As Document
Dim db As Database
On Error GoTo Error
Set db = CurrentDb
Set docs = db.Containers!Forms.Documents
docs.Refresh
For Each doc In docs
strTemp = doc.Name
DoCmd.OpenForm strTemp, acDesign, , , , acHidden
DoCmd.OpenModule "Form_" & strTemp
Set mdl = Modules("Form_" & strTemp)
next_doc:
DoCmd.Close acForm, strTemp, acSaveYes
Next doc
Set db = Nothing
Exit_Error:
Exit Sub
Error:
If Err.Number = 2517 Then
GoTo next_doc
Else
Msgbox Err.Number & " : " & Err.Description
End If
Resume Exit_Error
My problem is that when it gets to a form where the module has not been open at all since the form was created, then I get an error of 2517. That's fine. That is why I have the error handler, so that it goes to next_doc:. But when it gets to another form where the module has not been open at all since the form was created, the error handler does not catch and the error pops up. So basically the error handler is only working one time.
if that is confusing for you then just copy and paste this code under a button on a form and then create about 2 other forms without doing anything with them, just save them. Run the code, and see what happens. Then go open and close the modules to the forms that you haven't done anything with. You should now not get any problems. I can't figure out why it only does the error handlers once.
The code looks something like this:
Dim strTemp As String, mdl As Module
Dim docs As Documents, doc As Document
Dim db As Database
On Error GoTo Error
Set db = CurrentDb
Set docs = db.Containers!Forms.Documents
docs.Refresh
For Each doc In docs
strTemp = doc.Name
DoCmd.OpenForm strTemp, acDesign, , , , acHidden
DoCmd.OpenModule "Form_" & strTemp
Set mdl = Modules("Form_" & strTemp)
next_doc:
DoCmd.Close acForm, strTemp, acSaveYes
Next doc
Set db = Nothing
Exit_Error:
Exit Sub
Error:
If Err.Number = 2517 Then
GoTo next_doc
Else
Msgbox Err.Number & " : " & Err.Description
End If
Resume Exit_Error
My problem is that when it gets to a form where the module has not been open at all since the form was created, then I get an error of 2517. That's fine. That is why I have the error handler, so that it goes to next_doc:. But when it gets to another form where the module has not been open at all since the form was created, the error handler does not catch and the error pops up. So basically the error handler is only working one time.
if that is confusing for you then just copy and paste this code under a button on a form and then create about 2 other forms without doing anything with them, just save them. Run the code, and see what happens. Then go open and close the modules to the forms that you haven't done anything with. You should now not get any problems. I can't figure out why it only does the error handlers once.