首先,这是我在设计模式下的报告图片:
报告的基础查询返回如下值:
Allen Nelli 3:A,5:B,7:A,8:A, etc.
Breton Micheline 1:A,3:A,5:B,7:A, etc
Caporale Jody 1:A,3:A,5:B,7:A, etc
我必须使用子查询来获取连接数字:字母组合的第三个字段。这些值实际上代表日期和指定给计划中的特定班次。所以基本上,对于给定的月份,每个人都按照日值表示指定的班次。
目的是调用一个名为PopulateTextboxes(Value as String)的用户定义的公共函数,从文本框的ControlSource属性中报告的第一个文本框中调用它。查询中的第三个字段实际上名为Expr1,并且作为参数传递给函数。该函数用于填充所有具有相应字母名称的文本框:A或B或C或D等。运行报表时,函数本身不会被触发。
功能如下:
Public Function PopulateTextboxes(Expr As String) As String
'Each element of Expr should be a number followed by a colon followed by a letter: 10:A,12:B,15:C, etc.
Dim shiftData() As String
Dim Data As Variant
Dim i As Integer
Dim j As Integer
Dim temp() As String
Dim txt As TextBox
Dim rpt As Report
Dim strCtrl As String
If Expr = "" Then Exit Function
If IsNull(Expr) Then Exit Function
shiftData = Split(Expr, ",")
If UBound(shiftData) > 0 Then
'Make a 2D array
ReDim Data(UBound(shiftData), 2)
'Load up 2D array
For i = 0 To UBound(shiftData) - 1
If shiftData(i) <> "" Then
temp = SplitElement(shiftData(i), ":")
Data(i, 0) = temp(0)
Data(i, 1) = temp(1)
End If
Next i
Set rpt = Reports.item("Multi_Locations_Part_1")
If UBound(days) = 0 Then
MsgBox "days array not populated"
Exit Function
End If
'Populate each Textbox in the Multi_Locations_Part_1 Report
For i = 1 To UBound(days)
strCtrl = "txtDesig_" & CStr(i)
Set txt = rpt.Controls.item(strCtrl)
For j = 0 To UBound(Data) - 1
If Data(j, 0) = days(i) Then
txt.Value = Data(j, 1) 'A,B,C,etc.
Exit For
End If
Next j
Next i
End If
PopulateTextboxes = Expr
End Function
Private Function SplitElement(Value As String, Delim As String) As String()
Dim result() As String
result = Split(Value, Delim)
SplitElement = result
End Function
请告知。
答案 0 :(得分:0)
最好的方法是从详细信息部分的Format
事件中调用您的函数,以便为每条记录调用它。
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Call PopulateTextboxes(Me.Expr1)
End Sub
如果PopulateTextboxes
位于单独的模块中,建议您将Me
作为报告的附加参数,这样您就不必对报告名称进行硬编码。
另请注意,在分配对象变量时需要Set
关键字,例如
Set txt = rpt.Controls.item("txtDesig_" & CStr(i))