|
-
Feb 9th, 2000, 06:20 AM
#1
Thread Starter
New Member
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
-
Feb 9th, 2000, 06:31 AM
#2
PowerPoster
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
-
Feb 9th, 2000, 08:22 AM
#3
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|