Check form open or not?

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

Hi folk,

Does anyone know how to check a form is opened or not?

I tried something like this, but got an error message.

If forms!test.open = true then
Msgbox "Open"
else Msgbox "Not"
end if

Any help will be appreciated.

Thanks.

Tim.
 
Tim said:
Hi folk,

Does anyone know how to check a form is opened or not?


This will tell you if a form is open in any view or not:

Public Function IsOpenForm(strFormName As String) As Boolean
IsOpenForm = SysCmd(acSysCmdGetObjectState, _
acForm, strFormName)
End Function
 
Marsh,

The function is great. I also want to know how to check
the object(s) such as table, query, form and so on..
is/are exit or not.

Could you show me how?

Thanks a lot.

Tim.
 
Tim said:
Marsh,

The function is great. I also want to know how to check
the object(s) such as table, query, form and so on..
is/are exit or not.


First, I have a problem with an application that does not
"know" what's in it. It is a very rare situation where
there's a valid reason to do check if something exists.

One common question is to check if a table exists before
deleting it. But, the answer is that it is better to delete
the records in the table rather than delete the table
object. Either that or just delete the table and ignore the
error if it doesn't exist.

Alright, to answer your question, you can just reference an
object and if there's no error, then it exists. If there's
an error, then you have to check if the error is "not in the
collection" or if there's something more serious has gone
wrong. Here's two examples, a function for queries would
be the same as the one for tables except it would use the
QueryDefs collection. Functions for Reports and Modules
would be the same as the one for forms except for using the
"Reports" and "Modules" containers.

Public Function IsTable(strItemName As String) As Variant
Dim strTemp As String
On Error GoTo ErrHandler
strTemp = CurrentDb.TableDefs(strItemName).Name
IsTable = True
ExitHere:
Exit Function

ErrHandler:
Select Case Err.number
Case 3265
IsTable = False
Case Else
MsgBox Err.number & " - " & Err.Description
IsTable = Null
End Select
Resume ExitHere
End Function


Public Function IsForm(strItemName As String) As Variant
Dim strTemp As String
On Error GoTo ErrHandler
strTemp =
CurrentDb.Containers("Forms").Documents(strItemName).Name
IsForm = True
ExitHere:
Exit Function

ErrHandler:
Select Case Err.number
Case 3265
IsForm = False
Case Else
MsgBox Err.number & " - " & Err.Description
IsForm = Null
End Select
Resume ExitHere
End Function
 
Marsh,

All the codes are worked perfect. I just have one more
question. How to check the existent of Macros?

I tried to create a module simlier to form module but it
didn't work. Do you have any sugestion?

Thank you very much.

Tim.
 
Tim said:
Marsh,

All the codes are worked perfect. I just have one more
question. How to check the existent of Macros?

I tried to create a module simlier to form module but it
didn't work. Do you have any sugestion?

What the heck are you doing that you need to know if a macro
exists?? Except for AutoExec and AutoKeys, macros are next
to useless when it comes to building a "real" application.

Whatever ... Macro documents are in the Scripts container.
 
Marsh,

My question for Macro is for learning purpose.

Thanks a lot for your help.

Tim.
-----Original Message-----
Tim said:
Marsh,

All the codes are worked perfect. I just have one more
question. How to check the existent of Macros?

I tried to create a module simlier to form module but it
didn't work. Do you have any sugestion?

What the heck are you doing that you need to know if a macro
exists?? Except for AutoExec and AutoKeys, macros are next
to useless when it comes to building a "real" application.

Whatever ... Macro documents are in the Scripts container.
--
Marsh
MVP [MS Access]

Tim. ignore
the reference
an in
the using
the

.
 
Back
Top