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

Checking for existance of a FORM 1

Status
Not open for further replies.

beckwiga

Programmer
Mar 30, 2005
70
I'm stuck again. This is VBA in Access 2003. I am trying to check to see if a FORM exists in my db. My code here to check to see if a TABLE exists works, however, I don't know how to check for a FORM. Is there a FormDefs (like TableDefs) that I'm not aware of? Thanks to anyone in advance. This is still new to me.


Private Sub Events_DblClick(Cancel As Integer)

If ObjectExists("Form", "Form Name") Then
MsgBox "Success"
Else
MsgBox "Failure"
End If

'DoCmd.OpenForm Forms!MENU.Events, , , stLinkCriteria
'MsgBox (Forms!MENU.Events)

Exit_Events_DblClick:
Exit Sub

Err_Events_DblClick:
MsgBox Err.Description
Resume

End Sub



Here is the ObjectExists module code:

Function ObjectExists(strObjectType As String, strObjectName As String) As Boolean
Dim db As Database
Dim tbl As TableDef

Set db = CurrentDb()
ObjectExists = False

If strObjectType = "Form" Then
For Each tbl In db.TableDefs
If tbl.Name = strObjectName Then
ObjectExists = True
Exit Function
End If
Next tbl
End If

End Function
 
I'd try the AllForms collection in stead, perhaps something liket this?

[tt]dim frm as object
for each frm in currentproject.allforms
ObjectExists = (frm.name = strObjectName)
if ObjectExists then exit for
next frm[/tt]

Also check out the Access fora - there are seven of them (find them through the forum search at top)

Also, to open a form:

[tt]docmd.openform "frmFormName"[/tt]

Hit F1 while the cursor is within openform...

Roy-Vidar
 
Thanks, Roy. That seems to work well. I was trying to use Containers before your reply, but wasn't having much luck. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top