ACC2000: How to Determine If a Form Exists in a Database (210597)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q210597
Moderate: Requires basic macro, coding, and interoperability skills.

SUMMARY

This article shows you how to create a Visual Basic for Application procedure to determine if a form exists in a database. If the form is in the database, the function opens it; otherwise, you get a message box stating that the form does not exist in this database.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
Sub FormOpener(FormToOpen As String)

   Dim obj As AccessObject
   
   For Each obj In CurrentProject.AllForms
      If obj.Name = FormToOpen Then
         DoCmd.OpenForm FormToOpen
         Exit Sub
      End If
   Next
   
   MsgBox FormToOpen & " does not exist in this database."
   
End Sub
				

REFERENCES

For more information about the AllForms collection, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type allforms collection in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kbdta kbhowto kbProgramming KB210597