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!

Question about vba referrance 1

Status
Not open for further replies.

Lavenderchan

Technical User
Jul 21, 2008
132
US
Hi I've got a preview report that I've added to a form but I don't want it open and where else so I added this code
Private Sub Report_Open(Cancel As Integer)
If Not IsLoaded("Tracking Log") Then
MsgBox "Open this report using the Preview button on the Tracking Log form."
Cancel = True
End Sub
but its saying sub or function isn't found. I was wondering why the IsLoaded might not work. I did some reading to my understanding they added something to 2003 access with the IsLoaded but I'm not sure why its effecting my code now. Any insight would be helpful.
Keri
 
G'day keri,

Add this under your code or in a module and you should be golden

Code:
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet view.
    
    Const conObjStateClosed = 0
    Const conDesignView = 0
    
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
        If Forms(strFormName).CurrentView <> conDesignView Then
            IsLoaded = True
        End If
    End If
End Function

Good luck,

JB

 
Replace this:
If Not IsLoaded("Tracking Log") Then
with this:
If Not CurrentProject.AllForms("Tracking Log").IsLoaded Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top