pass PatID field when add new records

F

Frances

Thanks in advanced if anyone can help me out ASAP.

I have two forms, frm_searchPatient and frm_Labs. My intend is to click
AddLab button on the 1st form, then open the 2nd form to add additional
information to current PatID. The problem is that the datafield, PatID,
doesn't get passed to the frm_Labs.

Access VBA code of frm_searchpatient is the following:


Option Compare Database
Option Explicit

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 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

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
 
B

Brian Bastl

Hi Frances,

is frm_searchPatient unbound or does it have a recordsource? If the latter,
can you post it? Also, is [PatID] numeric or text?

Brian
 
F

Frances

It has a recordsource which is a query with PatID as key data field. PatID
is a text.
Thank you for your time.

Brian Bastl said:
Hi Frances,

is frm_searchPatient unbound or does it have a recordsource? If the latter,
can you post it? Also, is [PatID] numeric or text?

Brian

Frances said:
Thanks in advanced if anyone can help me out ASAP.

I have two forms, frm_searchPatient and frm_Labs. My intend is to click
AddLab button on the 1st form, then open the 2nd form to add additional
information to current PatID. The problem is that the datafield, PatID,
doesn't get passed to the frm_Labs.

Access VBA code of frm_searchpatient is the following:


Option Compare Database
Option Explicit

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 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

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
 
B

Brian Bastl

Hi Frances,

Generally, you'd pass the PatID value via the OpenArgs argument in your
DoCmd statement, and use the receiving form's On Load event to assign the
value to the correct control. Your variable 'stLinkCriteria' should be
filtering 'frm_Labs' based on a Lab value. Something like the following
(substituting your control and field names where applicable):


From your frm_searchPatient....

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 = "[LabID In Lab Table] =" & Me.MyLabControl

DoCmd.OpenForm stDocName, , , stLinkCriteria , acFormAdd, , Me![PatID]

Exit_AddLabs_Click:
Exit Sub

Err_AddLabs_Click:
MsgBox Err.Description
Resume Exit_AddLabs_Click

End Sub

'*************
Load event of frm_Labs....

Private Sub Form_Load() 'frm_Labs

If Not IsNull(Me.OpenArgs) Then
Me.PatID = Me.OpenArgs
End If

End Sub


HTH,
Brian


Frances said:
It has a recordsource which is a query with PatID as key data field. PatID
is a text.
Thank you for your time.

Brian Bastl said:
Hi Frances,

is frm_searchPatient unbound or does it have a recordsource? If the latter,
can you post it? Also, is [PatID] numeric or text?

Brian

Frances said:
Thanks in advanced if anyone can help me out ASAP.

I have two forms, frm_searchPatient and frm_Labs. My intend is to click
AddLab button on the 1st form, then open the 2nd form to add additional
information to current PatID. The problem is that the datafield, PatID,
doesn't get passed to the frm_Labs.

Access VBA code of frm_searchpatient is the following:


Option Compare Database
Option Explicit

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 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

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
 
F

Frances

Thanks Brian, It works very well.

Best,
Frances

Brian Bastl said:
Hi Frances,

Generally, you'd pass the PatID value via the OpenArgs argument in your
DoCmd statement, and use the receiving form's On Load event to assign the
value to the correct control. Your variable 'stLinkCriteria' should be
filtering 'frm_Labs' based on a Lab value. Something like the following
(substituting your control and field names where applicable):


From your frm_searchPatient....

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 = "[LabID In Lab Table] =" & Me.MyLabControl

DoCmd.OpenForm stDocName, , , stLinkCriteria , acFormAdd, , Me![PatID]

Exit_AddLabs_Click:
Exit Sub

Err_AddLabs_Click:
MsgBox Err.Description
Resume Exit_AddLabs_Click

End Sub

'*************
Load event of frm_Labs....

Private Sub Form_Load() 'frm_Labs

If Not IsNull(Me.OpenArgs) Then
Me.PatID = Me.OpenArgs
End If

End Sub


HTH,
Brian


Frances said:
It has a recordsource which is a query with PatID as key data field. PatID
is a text.
Thank you for your time.

Brian Bastl said:
Hi Frances,

is frm_searchPatient unbound or does it have a recordsource? If the latter,
can you post it? Also, is [PatID] numeric or text?

Brian

Thanks in advanced if anyone can help me out ASAP.

I have two forms, frm_searchPatient and frm_Labs. My intend is to click
AddLab button on the 1st form, then open the 2nd form to add additional
information to current PatID. The problem is that the datafield, PatID,
doesn't get passed to the frm_Labs.

Access VBA code of frm_searchpatient is the following:


Option Compare Database
Option Explicit

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 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

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
 

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