在MS ACCESS中生成报告详细信息部分时出错

时间:2018-10-10 22:11:59

标签: ms-access-2007

我有一个名为qryActive的查询。

这将返回我在患者数据库中拥有的所有活跃患者。 我正在使用此查询填充报告的详细信息部分:rpt_handover_concise。

此报告提供了各个患者的详细信息,并生成了一个字符串,显示了他们目前使用的所有缓解疼痛的方法。

运行代码时,它会到达具有唯一ID Patient_UID = 17的特定记录。

它通过代码工作,所有结果均应达到预期。但是,此后立即它再次调用该记录,并再次遍历代码,但是这次它更改了止痛的一些细节,导致调用了另一个子例程,该子例程不包含与该患者相关的数据。

查询的详细信息如下:

SELECT PatientDB.Patient_UID, PatientDB.Patient_ReferralDate, 
PatientDB.Patient_Surname, PatientDB.Patient_Firstname, 
PatientDB.Patient_CHI, Locations.Locations_Name, 
PatientDB.Patient_Referral, PatientDB.Patient_Notes, 
PatientDB.Patient_Active, PatientDB.Patient_NeedsReview, 
PatientDB.Adjuncts_Nil, PatientDB.Adjuncts_Other, 
PatientDB.Adjuncts_ITM, PatientDB.Adjuncts_ITF, 
PatientDB.Adjuncts_KetInf, PatientDB.Adjuncts_LidInf, 
PatientDB.Adjuncts_Block, PatientDB.Adjuncts_Cath, 
Analgesia_Primary.Analgesia_Name,     
Analgesia_Primary.Analgesia_UID, Locations.Locations_UID
FROM Analgesia_Primary INNER JOIN (Locations INNER JOIN 
PatientDB ON Locations.Locations_UID = PatientDB.Location) ON 
Analgesia_Primary.Analgesia_UID = PatientDB.Primary_Analgesia
WHERE (((PatientDB.Patient_Active)=True));

它过滤患者数据库以仅检索“活动”患者,并从其他表格中获取一些信息以供参考。

当我运行查询时,我得到的数据是完全正确的。

当我使用format_detail部分中的代码运行报告时:

Option Compare Database
Option Explicit

Private Sub Detail_Format(Cancel As Integer, FormatCount As 
Integer)
'run for each detail section of the form
On Error GoTo ErrHandler

Dim adjuncts As String
lblCatheter.Visible = False 'sets catheter refill label to 
invisible
txtRefill.value = "" 'resets value of text box
txtRefill.Visible = False 'hides refill text box

Select Case Patient_NeedsReview.value
Case True 'if needsReview = TRUE
lblPainReview.Visible = True 'show needs review label
Case False 'case if FALSE
lblPainReview.Visible = False 'hide label
End Select

If Me.Adjuncts_Nil.value = -1 Then
' if no adjuncts
txtAdjuncts.value = "No adjuncts" 'print this
Exit Sub
Else
Select Case Me.Adjuncts_Block.value
Case True 'if they have a nerve block
adjuncts = "Nerve block" + vbCrLf 'add this to adjuncts string
End Select

Select Case Me.Adjuncts_Cath.value
Case True 'if they have a nerve catheter
getCatheterRefill 'get information for refill
adjuncts = adjuncts + "Nerve Catheter" + vbCrLf 'add tis to 
string
Case False
lblCatheter.Visible = False 'hide catheter label
txtRefill.Visible = False
End Select

Select Case Me.Adjuncts_ITF.value 'if used ITF
Case True
adjuncts = adjuncts + "Intrathecal Fentanyl" + vbCrLf 'add to 
adjuncts string
End Select

Select Case Me.Adjuncts_ITM.value 'if used ITM
Case True
adjuncts = adjuncts + "Intrathecal Morphine" + vbCrLf
End Select

Select Case Me.Adjuncts_KetInf.value 'if used ketamine infusion
Case True
adjuncts = adjuncts + "Ketamine Infusion" + vbCrLf
End Select

Select Case Me.Adjuncts_LidInf 'if used lidocaine infusion
Case True
adjuncts = adjuncts + "Lidoncaine Infusion" + vbCrLf
End Select

Select Case Me.Adjuncts_Other.value 'if used any other adjuncts
Case True
adjuncts = adjuncts + "Other"
End Select

End If

Me.txtAdjuncts.value = adjuncts 'set value of adjuncts to 
complete string
Exit Sub

ErrHandler:

MsgBox Err.Number & ": " & Err.Description, vbOKOnly, "Error"

End Sub

Private Sub getCatheterRefill() 'subroutine to get catheter 
refill info
On Error GoTo ErrHandler

Dim sql As String 'sql string to run
Dim rst As DAO.Recordset 'new recordset
Dim refillTime As Date 'refill date/time variable
'write SELECT statement to get refill time / date from 
Catheter_Info table where Patient_UID matches
sql = "SELECT Refill FROM Catheter_Info WHERE [Catheter_Info]. 
[Patient_UID] = " & Me.Patient_UID & ";"
Set rst = CurrentDb.OpenRecordset(sql) 'opens recordset using 
query

If rst.RecordCount = 0 Then 'no records
lblCatheter.Visible = False
txtRefill.Visible = False
Exit Sub

Else
If IsNull(rst!Refill) Then
'refill will not be required
txtRefill.value = "Refill will not be needed"
lblCatheter.Visible = True
Else
refillTime = rst!Refill 'gets refilltime from recordset
lblCatheter.Visible = True ' shows label and textbox and writes 
refill time to textbox
txtRefill.value = refillTime
txtRefill.Format = "dd/mm/yy, hh:mm"
txtRefill.Visible = True
End If

End If

Exit Sub

ErrHandler:

MsgBox Err.Number & ": " & Err.Description, vbOKOnly, "Error"
Exit Sub

End Sub

format_details私有子对于在Patient_DB表中找到的每条记录运行两次。我不太清楚为什么会这样。

我已经删除了所有数据(因为它仅在测试阶段)并重置了所有自动编号等。添加3个新条目时似乎可以正常工作,尽管它仍然对每个条目运行两次format_detail,但是弄清楚。

以前,它第二次浏览此部分时,它正在读取的当前记录信息已更改,例如Adjuncts_Nil已从-1更改为0,Adjuncts_Cath已从0更改为-1,因此它将开始使用其他子例程来搜索疼痛导管信息(不适当)。

非常感谢任何想法,如果您想了解更多信息,请告诉我。

非常感谢,

杰夫

0 个答案:

没有答案
相关问题