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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass the current record to the next form

Status
Not open for further replies.

francesyang

Programmer
Mar 3, 2006
2
0
0
US
Thanks in advanced if anyone can help me out ASAP.

My intend is to click AddLab button from the form frm_searchPatient, then open the form frm_Labs to add additional information to current PatID. The problem is that the key, PatID, doesn't get passed to the frm_Labs.

Access VB code of frm_searchpatient is the following:


Option Compare Database ' Use database order for string comparisons.
Option Explicit ' Requires variables to be declared before they are used.


Private Sub PatID_Combo_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[PatID] = '" & Me![PatID_Combo] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Private Sub addLabs_Click()

On Error GoTo Err_AddLabs_Click
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm_Labs"
' Open Labs form in data entry mode and store PatientID in
' the form's OpenArgs property.
stLinkCriteria = "[PatID]=" & "'" & Me![PatID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

' Close Labs form.
'DoCmd.Close acForm, "frm_Labs"

' Give data entry control focus.
Forms![frm_Labs]!SpecNum.SetFocus

Exit_AddLabs_Click:
Exit Sub

Err_AddLabs_Click:
MsgBox Err.Description
Resume Exit_AddLabs_Click

End Sub

Private Sub Form_Current()
On Error GoTo Err_Form_Current
' If the Labs form is open, show current supplier's products.

Dim strDocName As String
Dim strLinkCriteria As String

strDocName = "frm_labs"
strLinkCriteria = "[PatID] = Forms![Labs]![PatID]"


Exit_Form_Current:
Exit Sub

Err_Form_Current:
MsgBox Err.Description
Resume Exit_Form_Current

End Sub

VB code for frm_Labs:

Private Sub PatID_AfterUpdate()
' If OpenArgs property isn't null, set PatID to value of form's OpenArgs
' property. OpenArgs will have a value if Labs form is opened by clicking
' AddLabs command button on Labs form.
If IsNull(Forms!Labs.OpenArgs) Then
Exit Sub
Else
Me!PatID = Forms!Labs.OpenArgs
End If

End Sub
Private Sub Form_Current()
On Error GoTo Err_Form_Current

' If the Labs form is open, show current PatID.

Dim strDocName As String
Dim strLinkCriteria As String

strDocName = "frm_labs"
strLinkCriteria = "[PatID] = Forms![Labs]![PatID]"


Exit_Form_Current:
Exit Sub

Err_Form_Current:
MsgBox Err.Description
Resume Exit_Form_Current

End Sub
 
I didn't read all your code, but...

Does the first form stay open? If not, you can leave it open, making it invisisble instead of closing it.

As long as the first form is open, you should be able to refer to any of the fields there, from the other form, like this:

Forms!FormName!ControlName

---
Jeremy Wallace
METRIX Lead Developer
Fund for the City of New York
http:// metrix . fcny . org
 
Thanks for the post. That is exact my problem. The 1st form stays open and the 2nd form does not load the ID. When close the 2nd form, all data fields are updated in the table except the ID field.
 
frances, why the ONCurrent Event?
strLinkCriteria = "[PatID] = Forms![Labs]![PatID]"??

strLinkCriteria is not a Module level sub?
just curious?

Secondly, if you open a form in datamode,
why use openargs or link criteria?

maybe your logic here, is incorrect

If IsNull(Forms!Labs.OpenArgs) Then
Exit Sub
Else
Me!PatID = Forms!Labs.OpenArgs
End If
I haven't used OpenArgs for a while,
so I forget if a form open in datamode,
will accept openargs.
...IsNull is always true???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top