MS Access - 打开包含新记录的表单并插入先前表单中的值

发布于 2024-10-11 00:15:21 字数 1159 浏览 5 评论 0原文

我在 MS Access 数据库中有一个表格,其中列出了带有订单号的订单,每页一个订单。表单底部有一个按钮,可打开另一个表单,为订单添加项目。

我正在尝试在 MS Access 中使用 vb 获取订单号并自动将其放入新项目的详细信息表单中的字段中。我尝试了不同的方法,但似乎建议使用 OpenArgs。但详细信息表单无法打开,并且出现运行时错误。 以下是问题的详细信息 - 我们将非常感谢您的建议:

相关的表格和字段是: 订单表格为 frmPedidoAvifiFind 包含一个订单的订单行的表单是 frmPedidoAvifi-dtlAdd(一种用于添加详细信息但不可查看现有详细信息的单独表单)。 两种表格上的订单号字段均为 PedidoAvifiNo。这是两个表中的数字字段,两个表通过该字段通过一对多关系链接。

主窗体: 按钮调出明细窗体,代码如下:

主窗体按钮上的代码:

Sub AddDetails_Click()
  Dim strDocName As String

    strDocName = "frmPedidoAvifi-dtlAdd"

    ' Open frmPedidoAvifi-dtl form in data entry mode and store PedidoAvifiNo in  the form's OpenArgs property.

    DoCmd.OpenForm strDocName, , , , acFormAdd, , [frmPedidoAvifiFind]![PedidoAvifiNo]

End Sub

明细窗体: 打开属性时

Private Sub Form_Open()
If Me.OpenArgs <> vbNullString Then
   Me.PedidoAvifiNo = Me.OpenArgs
End If

End Sub

测试1: 在主窗体上选择一个订单号,以便显示记录。 按 按钮添加订单行。 - 运行时错误“2465”找不到字段“|”提到的。调试突出显示 DoCmd 行。

测试2: 将 openform 行更改为: DoCmd.OpenForm strDocName, , , , acFormAdd, , Me.PedidoAvifiNo 结果: - 运行时错误 2501 openForm 操作被取消。

谢谢你, 迈克·冈纳 西班牙雷乌斯

I have a form in an MS Access database which lists Orders with an Order Number with one order per page. At the bottom of the form there is a button which opens another form, to add an item for the order.

I am trying to use vb in MS Access to take the order number and automatically put it in a field in the details form for the new item. I have tried different ways but using OpenArgs seems to be recommended. But the detail form won't open and I get run-time errors.
Here are the details of the problem - advice will be much appreciated:

The forms and field concerned are:
Form with orders is frmPedidoAvifiFind
Form with order-lines for one order is frmPedidoAvifi-dtlAdd (a separate form for adding details but not for viewing existing ones).
Field on both forms for Order Number is PedidoAvifiNo. This is a numeric field in both tables which are linked by a one-to-many relation via this field.

Main form: Button bring up detail form, code as follows:

Code on main form button:

Sub AddDetails_Click()
  Dim strDocName As String

    strDocName = "frmPedidoAvifi-dtlAdd"

    ' Open frmPedidoAvifi-dtl form in data entry mode and store PedidoAvifiNo in  the form's OpenArgs property.

    DoCmd.OpenForm strDocName, , , , acFormAdd, , [frmPedidoAvifiFind]![PedidoAvifiNo]

End Sub

Detail form: On Open property

Private Sub Form_Open()
If Me.OpenArgs <> vbNullString Then
   Me.PedidoAvifiNo = Me.OpenArgs
End If

End Sub

Test 1: select an order number on main form so that record shows.
Press button to add orderline. - run-time error '2465' can't find the field "|" referred to. Debug highlights the DoCmd line.

Test 2:
Change openform line to:
DoCmd.OpenForm strDocName, , , , acFormAdd, , Me.PedidoAvifiNo
result: - run-time error 2501 the openForm action was canceled.

Thank you,
Mike Gunner
Reus, Spain

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追风人 2024-10-18 00:15:21

您收到的错误意味着您拼写错误了控件的名称 PedidoAvifiNo

当您输入 Me. 时,智能感知将为您提供可用字段的列表,查看与 PedidoAvifiNo 类似的内容,或检查属性。很容易切换一个字母而不被注意。

对于第二部分,您应该使用 Load 事件,而不是 frmPedidoAvifi-dtlAdd 上的 Open 事件,因为控件在 Open 事件中尚不可用。

The error you are getting means that you have misspelled the name of the control PedidoAvifiNo.

When you type Me. intellisense will give you a list of available fields, see what you have that is similar to PedidoAvifiNo, or check the properties. It can be very easy to switch one letter and not notice.

As for the second part, you should use the Load event, rather than the Open event on frmPedidoAvifi-dtlAdd, because the controls are not yet available in the Open event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文