Prevent opening report from database window

  • Thread starter Thread starter Chuck
  • Start date Start date
C

Chuck

How can I prevent a report from being opened from the database window ? It
should be able to be opened from a form in print preview mode though. I do
not want to hide the database window, at least not yet. I'm looking for
some code to run from the report's OnOpen event.

Thanks
 
How can I prevent a report from being opened from the database window ? It
should be able to be opened from a form in print preview mode though. I do
not want to hide the database window, at least not yet. I'm looking for
some code to run from the report's OnOpen event.

Thanks

If you do not already have the IsLoaded function on your computer,
place the following function in a module:

Function IsLoaded(ByVal strFormName As String) As Integer
' 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
======
Then code the Report's Open event:
If Not IsLoaded([FormName]) Then
MsgBox "You must run this report from the form 'FormName'")
Cancel = True
End If
 
That is what I am using now but the report will open if the form specified
is open. I would prefer if the report could not be opened at all from the
database window.


How can I prevent a report from being opened from the database window ? It
should be able to be opened from a form in print preview mode though. I do
not want to hide the database window, at least not yet. I'm looking for
some code to run from the report's OnOpen event.

Thanks

If you do not already have the IsLoaded function on your computer,
place the following function in a module:

Function IsLoaded(ByVal strFormName As String) As Integer
' 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
======
Then code the Report's Open event:
If Not IsLoaded([FormName]) Then
MsgBox "You must run this report from the form 'FormName'")
Cancel = True
End If


--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.
 
Chuck said:
How can I prevent a report from being opened from the database window ? It
should be able to be opened from a form in print preview mode though. I do
not want to hide the database window, at least not yet. I'm looking for
some code to run from the report's OnOpen event.


Why do you care? Seriously, If the report is not dependent
on the form, then it won't matter how it's opened

If the report is dependent on the form, then the open event
should check if the form is open with valid values and
cancel the report if the requirements are not met. This can
be done by referencing a control on the form and trapping
the error if the form is not open:

On Error GoTo ErrHandler
var = Forms!theform.somecontrol
. . .
Exit Here:
Exit Sub

ErrHandler:
Cancel = True
Resume ExitHere
End Sub

If you want to make sure the form is used to filter the
report using the OpenReport method's WhereCondition
argument, then it gets trickier. You'll need a module level
Public variable in a standard module that you set to true
just before opening the report. Then the report's Open
event can test the variable and cancel the report if it's
false. If it's true, reset the variable to false and
proceed with the report.
 
Back
Top