动态填充后在另一个(未绑定的)表单中显示表单
Posted
技术标签:
【中文标题】动态填充后在另一个(未绑定的)表单中显示表单【英文标题】:Displaying a Form inside another (unbound) Form after it has been dynamically filled 【发布时间】:2021-07-11 00:44:16 【问题描述】:我有一个表单(名为:List_Items),它有几个控件,一个是一个带有项目的列表框,当一个项目被选中时,它被添加到不同的列表框(在同一个表单上,用于重新排序),一次全部重新订购商品有一个 cmd 按钮,可以将这些商品保存到数据库的“订单”表中,然后该数据将填写第三个表格“Orders_Print”(如下所述),然后将第三个表格保存为 PDF 'DoCmd.OutputTo acOutputForm、frmName、acFormatPDF、fileName'(下面列出的子目录)。这一切正常。
我有第二个表单(名为:订单),它有几个控件,一个是带有(订单)日期的列表框。
我有第三个表单(名为:Orders_Print),上面有一些控件,这些控件是从模块中的子填充的。
我希望将第三个表单“Orders_Print”显示在第二个表单“Orders”中以便于阅读。我正在尝试使用子表单控件。我可以让子窗体的 form 显示正确的数据,但不能让子窗体 control 在其父窗体中显示此数据。截至目前,“订单”上的日期列表框将传递一个日期给模块中的子,正确填写第三个表单“订单_打印”,打开订单_打印表单,但子表单控件不显示任何数据,它只会显示最初保存在 Orders_Print 表单中的所有静态数据。
一切正常,除了我无法在“订单”表单中显示“订单打印”表单。
尝试“链接”但收到未绑定的表单错误,并且理解不够,无法手动链接(如果可能)。
还尝试重新查询很多东西(而且顺序也不同)。
Me.Requery
subOrderDetails.Requery
subOrderDetails.Form.Requery
subOrderDetails.Form.Controls("txtVender").Requery
希望您可以从下面的屏幕截图中了解正在发生的事情以及我正在努力实现的目标。
这里是填写“Order_Print”的Sub。
sub 的主要原因是格式化列表框中的 Desc,我希望它以多行显示,如图 2 所示。
Public Sub saveAsPDF(frmName As String, PO As String, Optional subForm As Boolean = False)
DoCmd.OpenForm frmName
Dim frm As Form
Set frm = Forms(frmName)
frm.Visible = True
If subForm = True Then
' frm.Visible = False ' testing
End If
frm.txtVender = ""
frm.txtPO = ""
Dim ii As Integer
With frm.lstOrderItems
For ii = .ListCount - 1 To 0 Step -1
.RemoveItem (.ListCount - 1)
Next ii
End With
Dim fileName As String
Dim vender As String
Dim orderDateIs As String
' ItemID
Dim rs As DAO.Recordset
Dim sSQL As String
Dim i As Integer
sSQL = "SELECT Orders.*, Items.ID, Items.VenderSKU as VenderSKU,Items.VenderItemName as ItemName, Venders.ID, Venders.VenderName as VenderName"
sSQL = sSQL & " FROM (Orders INNER JOIN Items ON Orders.ItemID = Items.ID) "
sSQL = sSQL & " left JOIN Venders ON Orders.VenderID = Venders.ID"
sSQL = sSQL & " WHERE Orders.PO = '" & PO & "'"
Set rs = getRecord(sSQL)
Call Forms.Orders_Print.setLstItems
Do While Not rs.EOF
i = i + 1
vender = rs!VenderName
orderDateIs = Format(rs!OrderDate, "yyyy.mm.dd-hh.mm.ssAM/PM")
orderDateIs = Replace(orderDateIs, "AM", "")
orderDateIs = Replace(orderDateIs, "PM", "")
frm.txtVender = vender
frm.txtOrderDate = Format(rs!OrderDate, "Short Date")
frm.txtOrderTotalCost = rs!TotalOrderCost
Dim itemLen As Integer
Dim itemNameShort As String
Dim itemNameShortBuild As String
Dim itemNameShortBuildArray()
Dim x, y, z As Integer
Dim splitStringAt As Integer
Dim spl As Variant
x = 0
y = 0
z = 0
splitStringAt = 73
itemNameShort = rs!ItemName
'itemNameShort = Replace(rs!ItemName, ",", "")
spl = Split(itemNameShort, " ")
If Len(itemNameShort) > splitStringAt Then
For x = 0 To UBound(spl)
itemNameShortBuild = itemNameShortBuild & spl(x) & " "
If Len(itemNameShortBuild) < splitStringAt Then
itemNameShort = itemNameShortBuild
Else
ReDim Preserve itemNameShortBuildArray(y)
itemNameShortBuildArray(y) = itemNameShort
itemNameShortBuild = ""
y = y + 1
x = x - 1
End If
Next x
ReDim Preserve itemNameShortBuildArray(y)
itemNameShortBuildArray(y) = itemNameShort
itemNameShortBuild = ""
itemNameShort = ""
Else
ReDim Preserve itemNameShortBuildArray(0)
itemNameShortBuildArray(y) = itemNameShort
End If
itemNameShortBuild = ""
itemNameShort = ""
For z = 0 To UBound(itemNameShortBuildArray)
If z = 0 Then
frm.lstOrderItems.AddItem rs!VenderSKU & ";'" & itemNameShortBuildArray(z) & "';" & rs!OrderQTY & ";$" & rs!TotalItemCost
Else
frm.lstOrderItems.AddItem ";'" & itemNameShortBuildArray(z) & "';;"
End If
Next z
frm.lstOrderItems.Selected(i) = False
rs.MoveNext
frm.txtPO = PO
Loop
If subForm = False Then
fileName = projectPath & "POs\" & vender & "\"
Call makeDir(fileName)
fileName = fileName & "PO." & PO & "_" & vender & "_" & orderDateIs & "_" & currentUserName & ".pdf"
DoCmd.OutputTo acOutputForm, frmName, acFormatPDF, fileName
DoCmd.Close acForm, frmName, acSaveNo
Call runit(fileName)
End If
End Sub
【问题讨论】:
【参考方案1】:搞定了……
需要“通过”父表单填充 subform.control.form。我试图填充子表单本身,然后在父表单中“刷新”它。
更改了 Sub 的顶部
来自
DoCmd.OpenForm frmName
Dim frm As Form
Set frm = Forms(frmName)
frm.Visible = True
If subForm = True Then
' frm.Visible = False ' testing
End If
到
Dim frm As Form
If subForm = True Then
Set frm = Forms("Orders").subOrderDetails.Form
Else
DoCmd.OpenForm frmName
Set frm = Forms(frmName)
frm.Visible = True
End If
【讨论】:
以上是关于动态填充后在另一个(未绑定的)表单中显示表单的主要内容,如果未能解决你的问题,请参考以下文章
Flask WTForms 动态表单依赖项 selectField 未填充在编辑页面中