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
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