I'm assuming that by 'file' you don't mean a file as such, but rather a form
object in the current database, as its forms you seem to want to open.
This sounds rather like something I once did in the days before Doris Day
was a virgin with a form for editing technical 'glossaries', which were
really just lists of valid terms for a particular category of data. The way
it worked was by having a list box on the left, which listed all the
different categories, and a subform control on the right of a form. When a
category was selected in the list box the source for the subform control was
set to the relevant form which listed the terms for that category. I realize
now I could have done it a lot more efficiently by linking a single subform
based on a query so that it only showed the relevant rows, but I was pretty
green in those days! Nevertheless it serves to answer your question because
it did just what you have in mind.
The list box was based on a query on a table with two columns, Glossary and
Glossary_Form, the first column containing the categories listed in the list
box, the second the name of the form which goes with that category, so if
"Geology – Drift" is selected in the list box the form name is
"fsubGeology_Drift_Gloss". This form is then shown in the subform control
with the following code in the list box's AfterUpdate event procedure:
On Error GoTo Err_Handler
Dim strErrorMessage As String
' Make subform control visible if hidden
If Me!sfcGlossary.Visible = False Then
Me!sfcGlossary.Visible = True
End If
'Set source object for subform control
Me!sfcGlossary.SourceObject = Me!lstFormList.Column(1)
Exit_Here:
Exit Sub
Err_Handler:
strErrorMessage = Err.Description & " (" & Err.Number & ")"
MsgBox strErrorMessage, vbExclamation, "Error"
Resume Exit_Here
where sfcGlossary is the name of the subform control, i.e. the control
which houses the subform, and lstFormList is the name of the list box.
The list box's RowSource is:
SELECT Glossary, Glossary_Form
FROM Glossaries
ORDER BY Glossary;
and its ColumnCount property is 2. Note that the Column property is
zero-based so Column(1) in the above code refers to the second column,
Glossary_Form. Its Column Widths property is 8cm;0cm (Access will convert
this to inches if you are using imperial units).
While in the above example the subforms are all very similar it would work
with subforms which have no connection with each other. All you need is a
table of descriptive terms to appear in the list box and a form name to go
with each one. The only limitation is that they all need to fit into the
same size subform control on the main form; unless you want to be really
fancy, that is, and manipulate its size at runtime de4pending on which source
for the subform control is selected.
Ken Sheridan
Stafford, England