Multiple Instances problem

J

Jordan

My main form (called Patient Records) is a tab form with
different sub forms on each tab page. My problem is that
when I open the form using the a button with the code
below, none of my calculations that reference fields on
these different tab pages works! It gives a #Name?
error. Any new instances I open from the button on the
main form have the same problem. However, when I open
the form independent of this code, there is no problem,
nor is there any problem with the added instances. This
of course leads me to believe that my code to open the
initial instance has problems. How it works is that I
have a button on my Main Menu to open the search dialog
box (called SearchBox). After searching, the results are
displayed in a continuous subform with the button
containing this code as part of each of the continuous
records. Anybody have any ideas on what the problem
could be?

Private Sub ViewRecord_Click()

Dim frm As Form
Dim lngHwnd As Long
Dim blnFound As Boolean

If IsNumeric(Forms.searchbox.CalledFrom) Then
'Find the calling form
lngHwnd = Forms.searchbox.CalledFrom
For Each frm In Forms
If frm.hWnd = lngHwnd Then

'Find this record in that form.
With frm.RecordsetClone
.FindFirst "[ID]=" & Me![ID]
If Not .NoMatch Then
frm.Bookmark = .Bookmark
blnFound = True
End If
End With
Exit For

End If
Next
Else
Set frm = New [Form_Patient Records]
frm.Visible = True
frm.Caption = "Patient Records: " & Now()

'Append it to collection
clnPatientRecords.Add Item:=frm, Key:=CStr
(frm.hWnd)

'Find this record in that form.
With frm.RecordsetClone
.FindFirst "[ID]=" & Me![ID]
If Not .NoMatch Then
frm.Bookmark = .Bookmark
blnFound = True
End If
End With

DoCmd.Close acForm, "SearchBox"
End If

If blnFound Then
'Focus on the calling form, and close this one.
frm.SetFocus
Set frm = Nothing
DoCmd.Close acForm, "SearchBox"
Else
Beep
End If

Set frm = Nothing

End Sub
 
J

Jordan

No takers on this one? If anyone can help me figure this
out, I'd really appreciate it. Thanks.
 

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