在变化的事件处理程序获取文本框的值文本框、事件、程序

2023-09-08 11:01:53 作者:Garbage(废物)

我已经写了执行查询异步作为文本键入到一个文本框,但是我有点武断似乎得到下面的错误时,抛出一个表格:你不能引用的属性或方法为控制除非控制具有焦点。

I've written a form that performs queries asynchronously as text is typed into a textbox, however I somewhat arbitrarily seem to get the following error thrown: "You can't reference a property or method for a control unless the control has focus."

的直接相关的code是:

The immediately relevant code is:

Dim UpdateRequested As Boolean
Dim qryText As String

.
.
.

Private Sub txtBox_Change()
    qryText = txtBox.Text
    UpdateRequested = true
End Sub

在椭圆有些地方是code处理动态加载一个ADODB记录集,填充本地表,并刷新子表单。然而,即使我禁用此code,问题仍然存在:有时我得到的错误。有时候,我不知道。

Some place in the ellipses is the code that handles dynamically loading an ADODB record set, populating a local table, and refreshing a sub form. However, even when I disable this code, the problem persists: Sometimes I get the error. Sometimes I do not.

这似乎是持续通过关闭数据库并重新打开它。每次它再次开始工作,那是因为我一直打打闹闹与code在调试器,但我不知道究竟是什么导致它神奇地只是工作或者是什么原因造成它不工作所有的。

This seems to be persistent through closing the database and reopening it. Every time it starts working again, it's because I've been fooling around with code in the debugger, but I'm not sure what exactly is causing it to magically "just work" or what is causing it to not work at all.

只是为了让事情更令人费解的,我加了一些简单的事件处理程序:

Just to make things more puzzling, I added a couple of simple event handlers:

Private Sub txtBox_GotFocus()
    MsgBox "Got focus"
End Sub

Private Sub txtBox_LostFocus()
    MsgBox "Lost focus"
End Sub

我跑的形式。我点击测试盒。我收到得到重点的消息。当我键入​​不久,我看到错误,如上所述。如果我重新打开的形式,我可以有问题的文本框(其本身是未绑定)和绑定文本框之间的分表点击,看看这两个得到重点和失去焦点消息,因为人们所期望的。此外,显示了Screen.ActiveControl.Name的当前值一个消息框,显示文本属性被访问之前预期的名称。

I run the form. I click in the test box. I receive the "Got focus" message. As soon as I type I see the error as described above. If I re-open the form, I can click between the text box in question (which itself is unbound) and a bound text box in the sub form and see both "Got focus" and "lost focus" messages as one would expect. Furthermore, showing a message box with the current value of "Screen.ActiveControl.Name" shows the expected name just before the Text property is accessed.

推荐答案

我知道这是一个古老的线程,但它是第一个,我发现,当我有同样的问题。没有答案的帮助,除了Kaganar自己的解决方案,我指出了正确的方向。我猜的人之所以有烦恼再现错误是有一些重要的细节从Kaganar的描述丢失:

I know this is an old thread but it's the first I found when I had the same problem. None of the answers helped except Kaganar's own solution, which pointed me in the right direction. I'm guessing the reason people had trouble reproducing the error is there are some important details missing from Kaganar's description:

在文本框是在窗体页眉(或页脚)。 在该表格不允许添加。

由于我相信完整的答案是...

Because I believe the full answer is...

任何控件的Text属性是不可访问时,窗体上有一个记录源没有记录的修改

我觉得这是访问的一部分,不知道该文本框的存在:)要理解,可能出现约...

I think there is part of Access that does not realise the textbox exists :) To understand how that might come about...

将未绑定的文本框形式的细节 不得允许添加 设置将记录到返回任何记录 打开表格。

嘿preSTO!没有文本框。

Hey presto! No Textbox.

返回的记录,或允许添加或删除的记录源,等瞧!还有就是你的文本框与它的文本。

Return a record, or allow additions, or delete the recordsource, et Voila! There is your Textbox with it's Text.

 
精彩推荐
图片推荐