-
I've run into a problem where I have form names stored in a table on SQL server and then when selectivly retrieved and stored into a variable to be opened doesn't work.
For example:
If a have a Form call "frm_vbtest" in the SQL table and I retrieve that value and store it into a String Variable "FormName", I want to be able to pass that variable to the Load or Show command in order to display that form.
By being able to do this I don't have to hard code all my form names using Case statements.
Anyone have any ideas.
Thanks,
Ryan Grim
IS Admin
-
FormName has to be declared as a Form for that to work, e.g.
frmFormName As Form
However, if you are able to convert a string name into a Form type I don't know. You could try setting the Name property of the Form type to the name in your database, e.g.
frmFormName.Name = strFormName
That [i]mightp/i] work, give it a shot!
Regards,
------------------
- Chris
[email protected]
Q. Why do mice have small balls?
A. Not that many know how to dance :)
-
Here's a Function I wrote to do just what you're looking for:
Code:
Private Function FormByName(ByVal FormName As String) As Form
Dim oForm As Form
'Make sure Form isn't already Loaded..
For Each oForm In Forms
If LCase(oForm.Name) = LCase(FormName) Then
'If it is, Return a Pointer to it..
Set FormByName = oForm
Exit Function
End If
Next
'Not in the Collection, so Add it..
Set FormByName = Forms.Add(FormName)
End Function
Private Sub Command1_Click()
Dim oForm As Form
Set oForm = FormByName(Text1)
oForm.Show
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Certified AllExperts Expert