Pharma Down
Registered User.
- Local time
- Today, 10:18
- Joined
- Dec 1, 2011
- Messages
- 67
[My understanding of coding is nil (as you'll know if you have seen my other posts), so sorry if this query is too simple and should be posted elsewhere!]
I have a form that displays a list of 'active' records that are read/accessed on a different form - like a menu, showing the title/date of the record. Because of the way these records are created some might be linked to a patient (it's a healthcare info database) or not, but all will have a record (intervention) ID. If the recod is not linked to a patient the foreign key (Patient_ID) =0 (null?).
At the moment, to access the records I have two buttons:
- one opens patient linked records (Patient_ID = 1,2,3 etc): an intervention subform within a patient details form
- the other button opens the intervention (sub)form on its own with no patient details form, because no patient is linked.
This works, but is clumsy... if you click the patient-linked button where there is no patient you open the form with no record. This is what the code looks like for the two buttons:
Private Sub btn_open_Frm_interventions_Click()
On Error GoTo Err_btn_open_Frm_interventions_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Frm_interventions"
stLinkCriteria = "[intvn_ID]=" & Me![intvn_ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_btn_open_Frm_interventions_Click:
Exit Sub
Err_btn_open_Frm_interventions_Click:
MsgBox Err.Description
Resume Exit_btn_open_Frm_interventions_Click
End Sub
-------
Private Sub btn_opne_Frm_patient_interventions_Click()
On Error GoTo Err_btn_opne_Frm_patient_interventions_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Frm_patient_interventions"
stLinkCriteria = "[Patient_ID]=" & Me![Patient_ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_btn_opne_Frm_patient_interventions_:
Exit Sub
Err_btn_opne_Frm_patient_interventions_Click:
MsgBox Err.Description
Resume Exit_btn_opne_Frm_patient_interventions_
End Sub
I have been doing a little reading, to try to understand the coding a little better and have come across iif and IsNull.
Assuming that when an intervention is not linked to a patient (the form displays Patient_ID=0) this is a 'null,' could I use one button to open one form or the other? Something like:
iif (IsNull([Patient_ID]), open-the-intervention-form-linked-by-intvn_ID, open-the-patient-intervention-form-linked-by-Patient_ID
Obviously, I don't know how to go about combining all the code for the two buttons, especially since stLinkCriteria could refer to two things!
Is this possible?
The code (in blue) is created by the button wizard - I don't know which bits are actually necessaary!
Andy
I have a form that displays a list of 'active' records that are read/accessed on a different form - like a menu, showing the title/date of the record. Because of the way these records are created some might be linked to a patient (it's a healthcare info database) or not, but all will have a record (intervention) ID. If the recod is not linked to a patient the foreign key (Patient_ID) =0 (null?).
At the moment, to access the records I have two buttons:
- one opens patient linked records (Patient_ID = 1,2,3 etc): an intervention subform within a patient details form
- the other button opens the intervention (sub)form on its own with no patient details form, because no patient is linked.
This works, but is clumsy... if you click the patient-linked button where there is no patient you open the form with no record. This is what the code looks like for the two buttons:
Private Sub btn_open_Frm_interventions_Click()
On Error GoTo Err_btn_open_Frm_interventions_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Frm_interventions"
stLinkCriteria = "[intvn_ID]=" & Me![intvn_ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_btn_open_Frm_interventions_Click:
Exit Sub
Err_btn_open_Frm_interventions_Click:
MsgBox Err.Description
Resume Exit_btn_open_Frm_interventions_Click
End Sub
-------
Private Sub btn_opne_Frm_patient_interventions_Click()
On Error GoTo Err_btn_opne_Frm_patient_interventions_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Frm_patient_interventions"
stLinkCriteria = "[Patient_ID]=" & Me![Patient_ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_btn_opne_Frm_patient_interventions_:
Exit Sub
Err_btn_opne_Frm_patient_interventions_Click:
MsgBox Err.Description
Resume Exit_btn_opne_Frm_patient_interventions_
End Sub
I have been doing a little reading, to try to understand the coding a little better and have come across iif and IsNull.
Assuming that when an intervention is not linked to a patient (the form displays Patient_ID=0) this is a 'null,' could I use one button to open one form or the other? Something like:
iif (IsNull([Patient_ID]), open-the-intervention-form-linked-by-intvn_ID, open-the-patient-intervention-form-linked-by-Patient_ID
Obviously, I don't know how to go about combining all the code for the two buttons, especially since stLinkCriteria could refer to two things!
Is this possible?
The code (in blue) is created by the button wizard - I don't know which bits are actually necessaary!
Andy