Using A variable for form name

  • Thread starter Thread starter budz
  • Start date Start date
B

budz

Hi,

I have a set of tables and forms with the same names. I've
populated a listbox with the form/table names. I'd like to be able to
show a form upon clicking the name in the listbox or a button.

I've been trying diff things like the following (this is from a
button):

Text15 = Me.List10.ItemData(List10.ListIndex)
a = Text15.Text
a.Visible = True


which is not working. Is it possible to show a form using a
variable? Or is there another way of going about this?

Thanks!
 
I'm assuming Text15 is supposed to contain the name of a form?

As long as the form is open, use

Forms(Text15).Visible = True

If the form isn't open, that will generate a run-time error (since only open
forms are in the Forms collection)
 
budz,

Yes, you can do this. How depends on how many columns are in your listbox
(I have two in the table I use for this functionality with reports). In my
listbox, the first column is a text name that describes the report, and the
second, hidden column actually holds the name of the report. The way you
would implement this to open a form is something like:

Private sub cmd_OpenForm_Click

if ISNULL(me.lst_Forms) then
msgbox "Select a form to open"
me.lst_Forms.setfocus
else
docmd.openReport me.lst_Forms.column(1)
endif

end sub

HTH
Dale
 
Back
Top