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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check if a form exists in VBA code 1

Status
Not open for further replies.

beamerman

Technical User
Nov 14, 2001
16
AU
Using Access 97. I have a report that i use to print an invoice from a sales entry form. I also use another a form to reprint the invoice if required. I am trying to use the same report for both instances. I'm already using the me.args to pass the invoice number to the report and i need to display the word "reprint" if it is comming from the reprint form. Is there anyway to check if the form i use for the reprint is open so i can put some code into the report to see what form is calling the report?
Thanks in advance

Shane
 
Hi Beamerman,
This is from the Northwinds sample Db that ships with Access. It lives in a standard module:

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

You'd call this 'test' by code, probably in the reports on open event, something like:

If IsLoaded(&quot;TheNameOfTheFormYou'reLookingFor&quot;) Then
DoSomething
Else
DoSomethingElseorShowSomethingElse
End if

Hope that'll help!

;-)

Gord
gord@ghubbell.com
 
Thanks JoaTL and Gord for the ideas, I'll give it a try.
 
Just copied the code and it worked perfectly. Thanks Gord
LOL
 
Good morning and thank you beamerman. Actually thank Microsoft for including probably one of the most indispensable little functions you're ever going to use!
;-) Gord
gord@ghubbell.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top