Combo Box / List Box several events "open form"?!?

  • Thread starter Thread starter his-airness
  • Start date Start date
H

his-airness

Hi,
I have a problem with a combo box. I put a combo box on a new form
which includes a lot of peoples name. The way I want it to work is that
when I select one name from the drop down list it will open a new form
which includes the information of that person. So basically I need
several events saying "open form" instead just one. It works fine with
one value, but no matter what name you select from the combo box drop
down list it obviously just opens that one persons form with its
included information, since you can just add the one value to the box
(double click in design view/events/on click). So my question is: How
can I add several values (about 100) so that every person's own form
opens "on click"?
I'm pretty sure I can do the same thing in a list box and the same
problem will appear, so either way it would work if someone has a
solution for me.
Sorry if that might be a really easy question, but I'm a newbie and
don't know too much about the whole topic yet.
I appreciate any help and if my described problem doesn't work like I
wish it would maybe someone has a better idea to make it work similar.
Thank you very much.
 
You need to open mulitiple instances of the same form -

For each new instance you need an form object variable which you set using
the New keyword. Once you have the form open you can change it's
recordsource and caption.

Be careful!! Here are some things to watch:

- the form that you are instancing must have a module (ie it can not be a
lightweight form).

- the form object variable is the best way to refer to this new instance
since you will not be able to find the form in the forms collection (unless
you know it's index).

- As soon as your object variable goes out of scope, the new instance of the
form will automatically be destroyed (and closed).

Here's some sample code that uses the selected rows in a listbox to open
multiple instances of the customer form.

Note that col is declared in the Module header so that it stay's in scope
until the current module terminates.

Dim colForms As Collection
Private Sub Command2_Click()
Dim varItem As Variant
Dim frm As Form
Set colForms = New Collection
For Each varItem In Me.List0.ItemsSelected
Set frm = New Form_Customer
frm.RecordSource = "Select * from Customer " _
& "Where Custid=" & Me.List0.ItemData(varItem)
frm.Caption = "Customer: " & Me.List0.Column(1, varItem)
colForms.Add frm
Next varItem
End Sub

There is a sample mdb on www.daiglenet.com/msaccess.htm which may help you.
Also, take a look at the following articles:

ACC2000: How to Open Multiple Instances of a Form
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q210248

ACC: How to Open Multiple Instances of a Form
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q135369
 
Hello,
Thank you very much for your help. Do you think you could give me eas
step by step instruction, so I can apply what you have replied?
I'm really a newbie and don't know too much about all this coding an
how it works, so it would really help if you could tell me what button
to press and what to typ and set up...!
Thanks for your help again
 
Back
Top