当形式值为EOF时,添加新记录

发布于 2025-02-03 00:25:48 字数 670 浏览 2 评论 0原文

我有一个搜索栏和一个提交按钮,该按钮需要3个字符串,并从查询中从另一个表格上拉出记录。当记录存在于表中时,查询运行时,当我遇到一个错误时:

您输入了一个没有值的表达式,那是因为查询正在寻找一个记录存在。

当查询找不到时,我打算创建一个新记录。我这样做了:

Private Sub Form_Load()

    If Recordset.EOF = True Then
    DoCmd.GoToRecord , , acNewRec
    Exit Sub
    End If
        
... do some more stuff that's not relavant ...

但是,这会失败

。它可以在Learn.microsoft.com上进行。在EOF下,它指出:

openRecordSet方法内部调用movefirst方法。因此,在一个空记录集上使用OpenRecordSet方法将BOF和EOF属性设置为true。 (有关失败的MoveFirst方法的行为,请参见下表。)

我一直在寻找添加新记录而不是错误而不是遥远的方法。我如何解决保留表格上的错误whist?我的理解是我需要以某种方式使eof.value false。

编辑尝试了这个 RecordSet.Addnew 错误:此操作被关联的对象取消

I've got a search bar and a submit button that takes 3 strings and pulls the record on another form from a query. When the record exists in the table the query runs, when it doesn't, I get a an error:

You entered an expression that has no value, that's because the query is looking for a record that doesn't exist.

It's my intention to create a new record when the query cannot find one. I did this:

Private Sub Form_Load()

    If Recordset.EOF = True Then
    DoCmd.GoToRecord , , acNewRec
    Exit Sub
    End If
        
... do some more stuff that's not relavant ...

But this fails on Do.Cmd with the error, You cannot go to the specified record.

I was able to determine that when the form loads, its EOF whatever that means, so I looked it up on learn.microsoft.com. Under EOF, it states:

An OpenRecordset method internally invokes a MoveFirst method. Therefore, using an OpenRecordset method on an empty set of records sets the BOF and EOF properties to True. (See the following table for the behavior of a failed MoveFirst method.)

I've been looking at ways to add a new record instead of the error and not got far. How do I resolve the error whist staying on the form? It's my understanding I need to make EOF.value False somehow.

EDIT Tried this
Recordset.AddNew
Error: This action was cancelled by an associated object

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文