-
Greetings,
I a have an Access database where I store all my forms by FormName along with a description. These forms are all part of the same project. What I would like to do is be able to select the form description from a DbGrid and have that form displayed. From the recordset I can place the name in a string var but that is as far as I get. Help! how can I go from var to screen?
-
Thats Calling FORM from Recordset - it's early...
-
You need to create a routine that will go thru the all the forms in your app, checking each form to see if its name is equal to the name ( or description) of the form you selected from the grid. You can't use the Forms collections, since this only looks at forms that are currently open... instead you have to use Containers.... Something like this
For i = 0 to CurrentDb.Containers(1).Documents.Count -1
if (grdSelection) = CurrentDb.Containers(1).Documents(i).Properties(8).Value then
'you have found the right form description
DoCmd.OpenForm CurrentDb.Containers(1).Documents(i).Name
End If
Next i
Bash
-
Bashfirst,
Thanks for the reply, however I am not using Access form objects. I am using forms developed in VB. The names and descriptions of these forms are stored in an Access database as text. I need to take the text apply it to a variable and say variable.show (which doesn't work). This is what I have so far:
Data2.RecordSource = "Select NameofForm from Menu_Mstr where MenuID = " & Data1.Recordset!MenuID
Data2.Refresh
Dim sform As String
sform = Data2.Recordset!NameofForm
What next?
-
Next try this:
Call OpenForm sForm
Sub OpenForm(sName as string)
Dim f as Form
For each f in Forms
if f.Name = sName then
f.open
exit for
End if
next
End sub
------------------
Regards,
Vit
[This message has been edited by Vit (edited 08-25-1999).]
-
Actually, Vit's solution has the same problem... the Forms collection only references the open forms, so your application would have to load all your forms for that to work.... then you could show them when appropriate. This is probably not the best way to go.... the alternative would be to create a procedure which takes the name of the form as a string, goes thru a Select Case and opens the appropriate form... This solution isn't as pretty but it would work.
Public Sub OpenFormByName (sFormName as String)
Select Case sFormName
Case "frmMain"
frmMain.Show
Case "frmDetail"
frmDetail.Show
Case Else
MsgBox "Oops"
End Select
Hope this helps.
Bash
-
bashfist,
You are right about Vit's solution. My goal is to try not to hard code the form names as in the Select case method, but I do not think I have a choice.
Anyway, thanks to the both of you.
Pmeredith
-
One last thought (as if we haven't already beat this one down)...
In essence you are trying to late bind a form. Since we can't do that, what about using a DLL to display each form. Those you _can_ late bind using the users selection from the recordset. This would avoid having o hard code the form names.
Bash