首页 > 解决方案 > 如何在访问中将文本框的多个值从一个表单传递到另一个表单

问题描述

我的库存数据库中有两种购买和销售表格。有时我需要直接在购买表格中显示购买出售。我已经看到其他类似的问题无法解决我的问题。我也试过如下:

Option Compare Database

Private Sub Command25_Click()
    MsgBox "Are you sure to show this purchase as direct sale?", vbYesNo, "Direct Sale"
    If vbYes Then
    DoCmd.OpenForm "SF02PurchasetoSale", acNormal, , , , , DirectSale
           
    End If
       
End Sub

Private Sub DirectSale()
    Forms![SF02PurchasetoSale].[TxnDate] = Me.TxnDate.Value
    Forms![SF02PurchasetoSale].[Hub] = Me.Hub.Value
    Forms![SF02PurchasetoSale].[Code] = Me.Code.Value
    Forms![SF02PurchasetoSale].[PurchasePrice] = Me.PurchasePrice.Value
    Forms![SF02PurchasetoSale].[QtySold] = Me.QuantityPurchased.Value
    
End Sub

这显示了 DirectSale 的 openargs 上的“编译错误:预期的函数或变量”。我真的需要一些帮助。谢谢...

标签: ms-access

解决方案


OpenArgs 是将值传递给 OpenForm 或 OpenReport 命令中指定的表单或报表。考虑:

DoCmd.OpenForm "SF02PurchasetoSale", acNormal, , , acFormAdd, , "DirectSale"

然后在 SF02PurchasetoSale 后面编写代码:

Private Sub Form_Load()
With Me
If .OpenArgs = "DirectSale" Then
    .[TxnDate] = Forms!Purchases.TxnDate
    .[Hub] = Forms!Purchases.Hub
    .[Code] = Forms!Purchases.Code
    .[PurchasePrice] = Forms!Purchases.PurchasePrice
    .[QtySold] = Forms!Purchases.QuantityPurchased
End If
End With
End Sub

推荐阅读