Opening a second instance of a form - Access97

W

WSF

I have read the Help file and searched Google and Access sites for info
on this problem, but still cannot get it to work.

Firstly I a job info form (Pop-up - Modal-No, Has Module - Yes). In that
form there may be a reference to a previous job, in a text box
[txtPreviousJobNo] (if no previous it reads "0").

By double clicking that text box (where it holds a valid previous job
number) I want to open a second instance of the same form with the data
of the previous job.

The first instance of the JobInfo Form is bound to the master data table
and is initially opened from another main form by:
DoCmd.OpenForm "frmJobInfo", , , "JobsNo = " & Me!txtJobNo
where [Me!txtJobNo] is a current job number. That works fine.

Then I have:
Public PreviousJobNo As Integer
Public frmMulti As Form
declared in a separate Module

In the [txtPreviousJobNo]text box in the JobInfo form Double-Click event
I am trying:

Set frmMulti = New Form_frmJobInfo
frmMulti.SetFocus

This opens the second instance of the form - great, but - it displays
the data from the first record of the master data table.

How can I have the second instance display the data based on the job no
in the [txtPreviousJobNo] text box? Then I have two forms open each
displaying the current and the previous job?

I have read of the implication's of using multiple instances of forms,
closing them etc., but have my own ideas on handling that assuming I can
get them to open correctly for me in the first place.

TIA

WSF
 
W

WSF

Hello Doug,
Yes, I had a look at that and it has helped me understand a lot about
instances etc... But his (and my) code merely opens another form with
the same (or sometimes other unwelcome) data.
I am trying to open a second instance of a form based on the value of a
field in the first instance.
Possible?

Otherwise I guess I can create clones of the form for each instance I
need and run them separately. (Usually just the one extra instance is
required).

Cheers,
Bill
 
D

Douglas J. Steele

You can pass a value to each instance and have logic in the form that uses
that value to determine what it displays. This can either be a hidden field
on the form or a module-level variable that's been declared as Public. If
you make a sub Public you can call it from outside the form.
 
B

Brian

WSF said:
I have read the Help file and searched Google and Access sites for info
on this problem, but still cannot get it to work.

Firstly I a job info form (Pop-up - Modal-No, Has Module - Yes). In that
form there may be a reference to a previous job, in a text box
[txtPreviousJobNo] (if no previous it reads "0").

By double clicking that text box (where it holds a valid previous job
number) I want to open a second instance of the same form with the data
of the previous job.

The first instance of the JobInfo Form is bound to the master data table
and is initially opened from another main form by:
DoCmd.OpenForm "frmJobInfo", , , "JobsNo = " & Me!txtJobNo
where [Me!txtJobNo] is a current job number. That works fine.

Then I have:
Public PreviousJobNo As Integer
Public frmMulti As Form
declared in a separate Module

In the [txtPreviousJobNo]text box in the JobInfo form Double-Click event
I am trying:

Set frmMulti = New Form_frmJobInfo
frmMulti.SetFocus

This opens the second instance of the form - great, but - it displays
the data from the first record of the master data table.

How can I have the second instance display the data based on the job no
in the [txtPreviousJobNo] text box? Then I have two forms open each
displaying the current and the previous job?

I have read of the implication's of using multiple instances of forms,
closing them etc., but have my own ideas on handling that assuming I can
get them to open correctly for me in the first place.

TIA

WSF

I would suggest that you do the following:

1. Make the form unbound by removing the value from it's RecordSource
property.

2. Add a method to the form, something like this:

Public Sub ShowJobNo(ByVal JobNo As Long)

Me.RecordSource = "SELECT * FROM JobInfo WHERE JobNo = " & JobNo
Me.Visible = True

End Sub

3. Stop using DoCmd.OpenForm to open the first instance. Instead,
whenever you want to open the form, do so using some code such as this:

Set frmMulti = New Form_frmJobInfo
frmMulti.ShowJobNo [JobNo]
 
M

Mike Gramelspacher

This is how I used Allen Browne's code to do what I needed it to do. Maybe
it will give you an idea. I have an Access 200 sample database here:
www.psci.net/gramelsp/Naturalizations_test.zip


Function OpenAForm(stFormName As String, Optional stFindthis As String, _
Optional IsFilter As Boolean)
'Purpose: Open an independent instance of a form. Form can open
'with a different filter than the main form, or a different record
source.
Dim frm As Form

' determine if a form name was passed, and if so
' open a new instance, show it, and set its caption.
If (Len(stFormName & "") > 0) Then
Select Case stFormName
Case "frmNaturalizations"
Set frm = New Form_frmNaturalizations
frm.Caption = "Naturalization Details 0" & frm.hWnd
Case Else
Exit Function ' nothing to do
End Select
End If

' determine if there is a criteria
If (Len(stFindthis & "") > 0) Then
If IsFilter = True Then ' filter form instance
frm.Filter = stFindthis
frm.FilterOn = True
frm.Visible = True
Else ' change recordsource of form instance
frm.RecordSource = stFindthis
frm.Visible = True
End If
End If

Select Case stFormName
Case "frmNaturalizations"
'add instance to collection
clnNaturalizationForm.Add Item:=frm, Key:=CStr(frm.hWnd)
Case Else
' nothing to do
End Select

Set frm = Nothing
End Function

Mike Gramelspacher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top