devxlogo

Get a reference to a form given its name

Get a reference to a form given its name

In some cases you might want to activate a form given its name, but VB doesn’t let you do it directly. However, it is easy to create a function that does it by iterating over all the forms in the current project:

' retrieve a reference to a form given its name' if there are multiple occurrences of a form, it' retrieves the first occurrence in the Forms collectionFunction GetForm(ByVal formName As String) As Form    Dim frm As Form    For Each frm In Forms        If StrComp(frm.Name, formName, vbTextCompare) = 0 Then            Set GetForm = frm            Exit Function        End If    NextEnd Function

See also  Does It Make Sense to Splurge on a Laptop?
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist