Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Reference in VBA

Status
Not open for further replies.

Hayton

Technical User
Oct 17, 2001
257
NZ
Hi Guys,
I have a form fsubFitments which is a subform for frmFleet.

When I run this code I get a message "MS Access can't find the form "fsubfitments". I guess I am not referencing the the form somehow, ie "frmFleet!fsubFitments"

Any suggestions would be appreciated.

'Check if the original data entry form with the list is open (This form might have been opened manually.)
If SysCmd(acSysCmdGetObjectState, acForm, "fsubFitments") <> conObjStateClosed Then
If Forms("fsubFitments").CurrentView <> conDesignView Then
IsFormLoaded = True
End If
End If

Hayton McGregor

 
The forms collection only contains open forms and does not include forms open as subforms. I doubt your code works. I would think what Duane is asking makes sense. However, to check if a form is loaded as a subform.

Code:
Public Function isSubFormLoaded(subFrmName As String) As Boolean
  Dim frm As AccessObject
  Dim ctrl As Access.Control
  For Each frm In CurrentProject.AllForms
    If frm.IsLoaded Then
      For Each ctrl In Forms(frm.name).Controls
        If ctrl.ControlType = acSubform Then
          If ctrl.Form.name = subFrmName Then
            isSubFormLoaded = True
            Exit Function
           End If
        End If
      Next ctrl
    End If
  Next frm
End Function
 
Hi Guys, thanks for your advice. I redisgned the app got the code to check if frmFleet is open and all worked well.

Hayton McGregor

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top