ACC97: Form_MyForm Referencing Breaks After Converting from 95 (167222)
The information in this article applies to:
This article was previously published under Q167222 Moderate: Requires basic macro, coding, and interoperability skills.
SYMPTOMS
When you run your code in Microsoft Access 97 after converting a database
from Microsoft Access 7.0, you may receive the following error message:
Compile error: User-defined type not defined.
CAUSE
You are referring to a code module of a form or report using the following
syntax in code, and the HasModule property of that form or report is set to
No:
Dim f as Form_Customers
Dim f as New Form_Customers
RESOLUTION
To resolve this issue, use one of the following methods:
- Manually set the HasModule property of the form(s) and/or report(s) you are referencing to Yes.
- Use the following syntax instead:
Dim f as Form
Set f = Forms!Customers
NOTE: Before the Set statement, you must programmatically check to
see if the form is open. If it isn't, first open the form using the
OpenForm method.
- Use the following code to programmatically set the HasModule property of all forms and reports to Yes.
NOTE: This will make all forms and reports non-lightweight objects,
and therefore may make them load more slowly. If you know you do not
need to reference all forms or reports with the above syntax, you may
want to go back through and manually change the HasModule property to
No for those objects.
Option Compare Database
Option Explicit
Sub SetHasModuleTrue()
On Error GoTo Err_SetHasModuleTrue
Dim MyDb As Database
Dim MyDoc As Document
Dim bolObjectState As Boolean
Dim strMessage As String
Set MyDb = CurrentDb ' Set the current dabatase.
' Run this section to set HasModule property to Yes for
' all the forms that don't already have HasModule set to Yes.
' Go through each form in the database.
For Each MyDoc In MyDb.Containers("Forms").Documents
' Get the state of the form.
bolObjectState = SysCmd(acSysCmdGetObjectState, acForm, _
MyDoc.Name)
If bolObjectState = 0 Then ' If the form is not open,
' Open the form in design view.
DoCmd.OpenForm MyDoc.Name, acDesign, , , , acHidden
' If the HasModule Property is No,
If Not Forms(MyDoc.Name).HasModule Then
Forms(MyDoc.Name).HasModule = True ' set HasModule to
' Yes.
DoCmd.Save acForm, MyDoc.Name ' Save the form.
End If
DoCmd.Close acForm, MyDoc.Name ' Close the form.
Else
' If the form is open but not in Design view,
If Forms(MyDoc.Name).CurrentView = 1 Then
' change the form to Design view.
DoCmd.OpenForm MyDoc.Name, acDesign
End If
' If the HasModule Property is No,
If Not Forms(MyDoc.Name).HasModule Then
Forms(MyDoc.Name).HasModule = True ' set HasModule to Yes
strMessage = "Form '" & MyDoc.Name & "' is already open."
strMessage = strMessage & " The HasModule Propterty has"
strMessage = strMessage & " been set to Yes. Would you"
strMessage = strMessage & " like to save and close the"
strMessage = strMessage & " form now?"
' Ask users if they want to save and close a previously
' opened form. If yes
If MsgBox(strMessage, vbYesNo + vbInformation) = _
vbYes Then
DoCmd.Save acForm, MyDoc.Name ' save the form.
DoCmd.Close acForm, MyDoc.Name 'Close the form.
End If
End If
End If
Next MyDoc ' Go to next form.
' Run this section to set HasModule property to Yes for
' all the Reports that don't already have HasModule set to Yes.
DoCmd.Echo False
' Go through each report in the database.
For Each MyDoc In MyDb.Containers("Reports").Documents
' Get the state of the report.
bolObjectState = SysCmd(acSysCmdGetObjectState, acReport, _
MyDoc.Name)
If bolObjectState = 0 Then 'If the report is not open
' Open the report in Design view.
DoCmd.OpenReport MyDoc.Name, acDesign
' If the HasModule Property is No,
If Not Reports(MyDoc.Name).HasModule Then
' set the HasModule to Yes.
Reports(MyDoc.Name).HasModule = True
DoCmd.Save acReport, MyDoc.Name ' Save the report.
End If
DoCmd.Close acReport, MyDoc.Name ' Close the report.
Else
' If the report is already open, open it in Design view.
DoCmd.OpenReport MyDoc.Name, acDesign
' If the HasModule Property is No,
If Not Reports(MyDoc.Name).HasModule Then
' set HasModule to Yes.
Reports(MyDoc.Name).HasModule = True
strMessage = "Form '" & MyDoc.Name & "' is already open."
strMessage = strMessage & " The HasModule Propterty has"
strMessage = strMessage & " been set to Yes. Would you"
strMessage = strMessage & " like to save and close the"
strMessage = strMessage & " report now?"
' Ask users if they want to save and close a previously
' opened report. If yes
If MsgBox(strMessage, vbYesNo + vbInformation) = _
vbYes Then
DoCmd.Save acReport, MyDoc.Name ' save the report.
DoCmd.Close acReport, MyDoc.Name 'Close the report.
End If
End If
End If
Next MyDoc ' Go to the next report.
DoCmd.Echo True
Exit_SetHasModuleTrue:
Exit Sub
Err_SetHasModuleTrue:
DoCmd.Echo True
MsgBox Err.Description
Resume Exit_SetHasModuleTrue
End Sub
REFERENCES
For more information about referencing forms or reports as described in
this article, search the Help Index for "multiple instances of form," or
ask the Microsoft Access 97 Office Assistant.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kberrmsg kbprb kbProgramming KB167222 |
---|
|