Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open 2 copies of the same form at once 1

Status
Not open for further replies.

OrionElectrotech

Technical User
Jun 19, 2008
27
GB
I have a simple database of candidates, where their data is displayed on a form (Candidate Information).
I have used some scripting (taken from this site I think!) to enable to user to open another window if they need to view 2 candidates at once (a command button on the form) -

Option Compare Database

Public clnCandidate As New Collection 'Instances of CANDIDATE INFORMATION.

Function OpenACandidate()
'Purpose: Open an independent instance of form CANDIDATE INFORMATION.
Dim frm As Form

'Open a new instance, show it, and set a caption.

Set frm = New [Form_CANDIDATE INFORMATION]
frm.Visible = True
frm.Caption = frm.Hwnd & ", opened " & Now()

'Append it to our collection.
clnCandidate.Add Item:=frm, Key:=CStr(frm.Hwnd)
Set frm = Nothing

DoCmd.Close acForm, "Open a new candidate window?"

End Function

Function CloseAllCandidates()
'Purpose: Close all instances in the clnCandidate collection.
'Note: Leaves the copy opened directly from database window/nav pane.
Dim lngKt As Long
Dim lngI As Long

lngKt = clnCandidate.Count
For lngI = 1 To lngKt
clnCandidate.Remove 1
Next
End Function


I also have a "Go To" command button on a search form that will display the Candidate Information form for a selected candidate -

Private Sub go_to_Click()
On Error GoTo Err_go_to_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "CANDIDATE INFORMATION"

stLinkCriteria = "[ca_Name]=" & "'" & Me![ca_name] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_go_to_Click:
Exit Sub

Err_go_to_Click:
MsgBox Err.Description
Resume Exit_go_to_Click

End Sub


Not having ANY vb knowledge, I have no idea if the 2 can be merged so that when viewing the selected candidate from the search it also opens in a new window??

Caroline
 
Hi Caroline,

I don't understand what your problem is exactly.
when you use your 'go to' buttons, it does open the "CANDIDATE INFORMATION" form, with the chosen candidate, so what is the problem
or I don't understand you right

Ja
 
Sorry, I wasn't very clear!

I need the "go to" button to open a NEW copy of the Candidate Information form (therefore leaving any previously opened versions still open). It doesn't currently.

Hope this is a bit clearer,

Caroline
 

I see,
I think you should try some thing like that:
first create the form
Code:
 Set frm = New [Form_CANDIDATE INFORMATION]
then make the filtering (I copied your string above)
Code:
frm.AllowFilters = true
frm.Filter = "[ca_Name]=" & "'" & Me![ca_name] & "'"
And maybe add (I'm not sure)
Code:
frm.Requery
and then
Code:
frm.Visible = True

Hope it helps, Ill be glad to hear
Ja
 
Unfortunately it doesn't work. A new CANDIDATE INFORMATION form appears briefly (although not linked to the selected candidate, just goes to the first in the list) but then closes straight away.

Caroline
 
This works for me
Form module
Code:
Private Sub go_to_Click()
On Error GoTo Err_go_to_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    OpenACandidate (Me.ca_name)
Exit_go_to_Click:
    Exit Sub
Err_go_to_Click:
    MsgBox Err.Description
    Resume Exit_go_to_Click
End Sub
Standard module
Code:
Public clnCandidate As New Collection    'Instances of CANDIDATE INFORMATION.

Public Sub OpenACandidate(strCA_Name As String)
    'Purpose:    Open an independent instance of form CANDIDATE INFORMATION.
    Dim frm As Form
    Set frm = New [Form_CANDIDATE INFORMATION]
    frm.Visible = True
    frm.Caption = frm.hWnd & ", opened " & Now()
    frm.Filter = "ca_Name= '" & strCA_Name & "'"
    frm.FilterOn = True
    'Append it to our collection.
    clnCandidate.Add Item:=frm, Key:=CStr(frm.hWnd)
    Set frm = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top