Form calling

Form calling
Robbie Freeland

Reader Robbie Freeland serves up this tip that lets you select a form to load based on what your user does.

You can dynamically load a VB form from any string value. This can be useful when you have an application that has to load one of a multitude of different forms based on different user-defined criteria. You could define the criteria and the form name to serve up in a database and create a very flexible and easily maintained environment.

'Dynamically Load a Form from a String Value

Private Sub Form_Load()
    'There must be a form called frmTest physically
    'in your test project for this to work.
    txtFormName = "frmTest"
End Sub

Private Sub cmdTestFormLoad_Click()
    'txtFormName is the name of a text box
    'residing on your calling form.
    'This could also be any string value, even
    'perhaps one stored in a database.
    LoadFormByName txtFormName
End Sub

Private Sub LoadDynamicForm(newFormName As String)
    Dim DynamicForm As Form
    Set DynamicForm = Forms.Add(newFormName)
    'The load statement can not be ommitted
    'in order for this to work as a compiled
    Load DynamicForm

End Sub

Thanks Robbie. For your interest in SearchVB, we will forward you a SearchVB denim shirt.

Robbie Freeland is currently a Systems Analyst with First North American National Bank (A Circuit City company). He has 13+ years experience creating solutions for financial institutions using MS Basic and Visual Basic.

Did this tip work for you? Let us know. Email us to sound off.

This was first published in January 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.