Test for the existance of an MS Access Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hallo there

I need to run a test (returning either true or false) on whether a
particular form exists within my MS Access application (Version 2003). The
'Isloaded' function works wonderfully for testing whether a form is open but
not whether or not the form actually exists.

Has any one got any ideas.

Many thanks for any help you can give me.
 
Hi,
you can either loop through CurrentProject.AllForms collection or query
MSysObjects system table
 
Try this

If DCount("*","MSysObjects","Type = -32768 And [Name] = '" & FormName & "'")
= 0 Then
Msgbox "Form doesnt exist"
else
msgbox "Form exist"
End if
 
Holy cow, Batman!

Why do something using undocumented structures, that could eaily change
in the next version of Access, when you can do it using the documented
object model, the relevant parts of which are very unlikely to change,
at all?

(untested)

function bFormExists (sFormName as string) as boolean
dim s as string
on error resume next
s = dbengine(0)(0).containers![forms].documents(sFormName).name
bFormExists = (err.number = 0)
exit function

HTH,
TC [MVP Access]
 
Back
Top