Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB4,VB5,VB6
Expertise: beginner
Jun 16, 2001

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 collection

Function 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
    Next
End Function
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap