Help with IF Report is Open statement

Liz_I3

Well-known Member
Joined
Dec 30, 2002
Messages
647
Office Version
  1. 2016
Platform
  1. Windows
Hi
How would you refer to a report as open or closed
I want to set an if statement i.e If report.[DailyD] is open then
runmacro "dailyTotal"
Else
docmd.close

ENd IF

But I do not know the correct syntex for If report.[DailyD] is open
I know is open is not correct.

Thanks
Liz
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
hi,liz

if you put this function in a normal module you can test if objects are open from whereever.....

Code:
Function fIsOpen(intobjtype, strobjname) As Boolean
Dim intObjState As Integer

intObjState = SysCmd(acSysCmdGetObjectState, intobjtype, strobjname)
fIsOpen = intObjState

End Function

then use this syntax to test....

Code:
If fIsOpen(acReport, "DailyD") Then
    DoCmd.RunMacro "DailyTotal"
Else
    DoCmd.Close
End If

look up syscmd in help, it does lots of other useful stuff too!
hth, stubby
 
Upvote 0
Thanks Stubby
I will give it a try. Iam having problems with a parameter query. I have created a form that the users can select from a list box the firs parameter. When the OK button is clicked It opens a macro that opens a report. The query behide the report has a second paramenter in its query grid ..to enter a date. It is all working well except it the user enters a date and then hits cancel rather that ok they receive an Action Fail message, when Halt is click on that message another message is given stating the report is not open.

So I hope I can fit your code in to stop all these messages. If you have any further suggestions Please let me know

Thank you again
Liz
 
Upvote 0
hi liz

don't think my first answer will be much use...

..i don't use macros much, but to avoid the messages i think you need to take control of the 2nd parameter before the report opens.

is there any reason that you can't add a text box to your existing form to grab the date before the user clicks OK? the button could then do all the work without further user intervention, giving you control.

i presume that you refer to the list box in your first query
=Forms!YourForm!YourListBox

so do the same for the date in the other query
=Forms!YourForm!YourTextBox

if i'm barking up the wrong tree (or just barking!) let me know...

sh :biggrin:
 
Upvote 0

Forum statistics

Threads
1,221,564
Messages
6,160,513
Members
451,655
Latest member
rugubara

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top