0

我正在尝试在 Microsoft Access 中生成一个报告,该报告应根据存储在名为 Checkup 的表中名为 Exams 的字段中的内容创建一个列表。

到目前为止,我有一个带有计算字段的报告和一个带有记录源考试的文本框。计算字段使用 Switch 函数生成列表;这是代码:

=Switch([Examenes]="BHC","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "Gb:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:",[Examenes]="BHC, VDRL","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "Gb:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:" & Chr(13) & Chr(10) & "VDRL:",[Examenes]="BHC, EGO, VDRL","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "GB:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:" & Chr(13) & Chr(10) & "VDRL:" & Chr(13) & Chr(10) & "EGO" & Chr(13) & Chr(10) & "Color:" & Chr(13) & Chr(10) & "Densidad:" & Chr(13) & Chr(10) & "Ph:" & Chr(13) & Chr(10) & "SO:" & Chr(13) & Chr(10) & "Proteinas:" & Chr(13) & Chr(10) & "CE:" & Chr(13) & Chr(10) & "LL:" & Chr(13) & Chr(10) & "FM:" & Chr(13) & Chr(10) & "Nitrito:" & Chr(13) & Chr(10) & "Cristales:",[Examenes]="BHC, EGH, EGO, VDRL","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "Gb:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:" & Chr(13) & Chr(10) & "VDRL:" & Chr(13) & Chr(10) & "EGO" & Chr(13) & Chr(10) & "Color:" & Chr(13) & Chr(10) & "Densidad:" & Chr(13) & Chr(10) & "Ph:" & Chr(13) & Chr(10) & "SO:" & Chr(13) & Chr(10) & "Proteinas:" & Chr(13) & Chr(10) & "CE:" & Chr(13) & Chr(10) & "LL:" & Chr(13) & Chr(10) & "FM:" & Chr(13) & Chr(10) & "Nitrito:" & Chr(13) & Chr(10) & "Cristales:" & Chr(13) & Chr(10) & "EGH" & Chr(13) & Chr(10) & "Protozoarios:" & Chr(13) & Chr(10) & "Metazoarios:")

代码运行良好,但是,我需要向 Switch 函数添加更多值,但我收到错误消息“文本太长,无法编辑”。由于这个字段是计算出来的,我不能只是去表格并添加更多字符或使其成为备忘录类型字段(或者我至少我不知道如何)。

这个问题有解决方法吗?我还尝试将代码放在报告中的 onLoad(或 OnOpen)事件中,但没有让它工作。访问给我编译错误:预期:列表分隔符或)

这是代码:

Private Sub Report_Open(Cancel As Integer)
Switch([Examenes]="BHC","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "Gb:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:",[Examenes]="BHC, VDRL","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "Gb:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:" & Chr(13) & Chr(10) & "VDRL:",[Examenes]="BHC, EGO, VDRL","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "GB:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:" & Chr(13) & Chr(10) & "VDRL:" & Chr(13) & Chr(10) & "EGO" & Chr(13) & Chr(10) & "Color:" & Chr(13) & Chr(10) & "Densidad:" & Chr(13) & Chr(10) & "Ph:" & Chr(13) & Chr(10) & "SO:" & Chr(13) & Chr(10) & "Proteinas:" & Chr(13) & Chr(10) & "CE
:" & Chr(13) & Chr(10) & "LL:" & Chr(13) & Chr(10) & "FM:" & Chr(13) & Chr(10) & "Nitrito:" & Chr(13) & Chr(10) & "Cristales:",[Examenes]="BHC, EGH, EGO, VDRL","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "Gb:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:" & Chr(13) & Chr(10) & "VDRL:" & Chr(13) & Chr(10) & "EGO" & Chr(13) & Chr(10) & "Color:" & Chr(13) & Chr(10) & "Densidad:" & Chr(13) & Chr(10) & "Ph:" & Chr(13) & Chr(10) & "SO:" & Chr(13) & Chr(10) & "Proteinas:" & Chr(13) & Chr(10) & "CE:" & Chr(13) & Chr(10) & "LL:" & Chr(13) & Chr(10) & "FM:" & Chr(13) & Chr(10) & "Nitrito:" & Chr(13) & Chr(10) & "Cristales:" & Chr(13) & Chr(10) & "EGH" & Chr(13) & Chr(10) & "Protozoarios:" & Chr(13) & Chr(10) & "Metazoarios:")
End Sub

任何帮助是极大的赞赏!

4

1 回答 1

1

尝试使用一个简单的Select ... Case构造:

Private Sub Report_Open(Cancel As Integer)

    Const BHC   As String = "BHC" & vbCrLf & "Hto:" & vbCrLf & "Gb:" & vbCrLf & "E:" & vbCrLf & "S:" & vbCrLf & "L:" & vbCrLf & "M:" & vbCrLf & "St:" & vbCrLf & "B:"
    Const VDRL  As String = vbCrLf & "VDRL:"    
    Const EGO   As String = vbCrLf & "EGO" & vbCrLf & "Color:" & vbCrLf & "Densidad:" & vbCrLf & "Ph:" & vbCrLf & "SO:" & vbCrLf & "Proteinas:" & vbCrLf & "CE:" & vbCrLf & "LL:" & vbCrLf & "FM:" & vbCrLf & "Nitrito:" & vbCrLf & "Cristales:"
    Const EGH   As String = vbCrLf & "EGH" & vbCrLf & "Protozoarios:" & vbCrLf & "Metazoarios:"

    Dim Value   As string

    Select Case Me!Examenes.Value
        Case "BHC"
            Value = BHC
        Case "BHC, VDRL"
            Value = BHC & VDRL
        Case "BHC, EGO, VDRL"
            Value = BHC & VDRL & EGO
        Case "BHC, EGH, EGO, VDRL"
            Value = BHC & VDRL & EGO & EGH
    End Select

    ' Display result.
    Me!YourUnboundTextbox.Value = Value

End Sub
于 2021-06-25T07:50:10.360 回答