Determining if a form is loaded in a query

  • Thread starter Thread starter Yair Sageev
  • Start date Start date
Y

Yair Sageev

Hi,

I have a query that can either get the ProjectTitle from the Projects Form
or from the Repairs Form. I'm trying to write a query that matches the
project title from either one of the forms, depending on which one is
loaded. I tried writing the following in the criteria of the query:

=IIf([Forms]![Projects], [Forms]![Projects]![ProjectTitle],
[Forms]![Repairs]![ProjectTitle])

Every time I run the query it asks me for [Forms]![Repairs]![ProjectTitle]
if the repairs form isn't loaded but the projects form is, and vice versa.
What am I doing wrong?

Thanks in advance.
 
Try this function:
Public 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

-ed
 
Back
Top