OpenForm

J

Jan Nielsen

In an Access adp project I've made a form displaying some information from a
SQL server.

This form is used in Form view and displaying a single record at a time.
The table behind contains a row which refers to another record within the
same table.
When I double click this reference (displayed as a drop down combobox), I
would like to open a new dialog displaying the referenced record.

This all work fine if I create a new form with another name (using
DoCmd.OpenForm). But as it's just another record in the same table, I would
like to open a second window with the same form. Like two instances of the
same form displaying different records in the table.
However when I try to open the second window it never appears, instead
strange things happen to the first window (some texts becomes bold).

Can I somehow open two instances of the same form ? or do I have to copy
the form so that I have two form which are exactly yhe same ?
I use Access 2000 so far. Would Access 2003 fix the problem ?


Thanks in advance,
Jan Nielsen
 
B

Brendan Reynolds

It can be done, but not using the OpenForm method ...

Option Compare Database
Option Explicit

Dim mfrm As Form

Private Sub Command5_Click()

Set mfrm = New Form_Form1
mfrm.Visible = True

End Sub

Note that the 'mfrm' variable is declared at module level, not within the
Click event procedure (otherwise it would go out of scope immediately) and
that it is refered to using the module name ("Form_Form1") rather than the
form name ("Form1").

I understand (I've never actually used this) that keeping track of forms
opened this way (so that, for example, you can close them again when you
want to) can be tricky.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
A

Arvin Meyer

Here's some working code to open another instance of a form passing the ID
of the record you want it to open to:

Private colForms As Collection 'global variable for storing the form
instances

Public Function CreateNewInstance(ByVal strKey As String)

Dim frm As Form_frmEvents

Set frm = New Form_frmEvents

With frm
.RecordSource = "SELECT * FROM tblEvents WHERE EventID = " & strKey
& ";"
.Visible = True
End With

If colForms Is Nothing Then Set colForms = New Collection
colForms.Add frm, strKey

Set frm = Nothing

End Function

Use it like:

Call CreateNewInstance(Me.lstEvents)

The above code will open as many new copies of frmEvents as you wish
(subject to memory limitations). I use it in the click event of a list box.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access Downloads
http://www.datastrat.com
http://www.mvps.org/access
 
J

Jan Nielsen

Thanks...

Both methods work ok for me, as I only have to open one extra instance at a
time.

I had some problems filtering in the new dialog though.
When using Filter and FilterOn the dialog was just grey the first time it
appeared, afterwards it looked ok.
Using RecordSource it works perfectly, I just have to set ServerFilter to
"". For some reason it contains the "parent" forms filter.


Kind regards,
Jan Nielsen
 
Top