Click to See Complete Forum and Search --> : Calling From from recordset
pmeredith
Aug 24th, 1999, 04:22 PM
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?
pmeredith
Aug 24th, 1999, 04:24 PM
Thats Calling FORM from Recordset - it's early...
bashfirst
Aug 24th, 1999, 06:14 PM
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
pmeredith
Aug 24th, 1999, 08:51 PM
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?
Vit
Aug 25th, 1999, 10:48 AM
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).]
bashfirst
Aug 26th, 1999, 12:40 AM
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
pmeredith
Aug 26th, 1999, 03:51 AM
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
bashfirst
Aug 26th, 1999, 04:03 PM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.