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 'executable. Load DynamicForm DynamicForm.Show 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.