MS Access VBA呼叫子项在第一次通过时有效,但在第二次不起作用 [英] MS Access VBA call sub works on the first pass but not on the second

查看:75
本文介绍了MS Access VBA呼叫子项在第一次通过时有效,但在第二次不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰壁了,我完全茫然了.

I have hit a wall and I am completely at a loss.

所以我在MS Access中有一个表格.在其中,我有一个文本框和一个按钮.当我在文本框中输入数字,然后单击按钮时,它将打开一个公共子目录,该子目录随后将运行一些查询,更新数据库,显示文本框,然后清除该文本框.这一切都完美地工作.

So I have a Form in MS Access. In it I have a single text box and a single button. When I type in a number in the text box and then click the button it opens a public sub which then runs a few queries, updates the database, displays a text box and then clears out the text box. This all works perfectly.

我的问题是尝试通过在文本框中单击Enter来执行完全相同的操作.最奇怪的是,在我打开表格后,代码可以正常工作,但是所有后续尝试都会产生以下错误,直到我关闭表格并重新打开它:

My issue is trying to do the exact same thing with hitting enter in the text box. The strangest thing is that the code works fine right after I open up the form, but all subsequent attempts give the following error until I close the form and reopen it:

Data type mismatch in criteria expression.

对于我的一生,我无法弄清楚为什么它第一次做到了我想要的,然后分崩离析.

For the life of me I cannot figure out why it does what I want the first time, then falls apart on me.

以下是完整的VBA代码供参考:

Here is the complete VBA code for reference:

    Option Compare Database
Public Sub Cut_Update()

    On Error GoTo Cut_Update_Err

        DoCmd.OpenQuery "UPDATE_WIP_Cut", acViewNormal, acEdit
        DoCmd.OpenQuery "UPDATE_LastRun", acViewNormal, acEdit

        MsgBox "Database Updated"
        [Forms]![Portal_02_Cut]![WO_Num].Value = ""
Cut_Update_Exit:
        Exit Sub

Cut_Update_Err:
        MsgBox Error$
        Resume Cut_Update_Exit

End Sub
'------------------------------------------------------------
' Return in Textbox
'
'------------------------------------------------------------
Private Sub WO_Num_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        Call Cut_Update
        Me.Refresh
    End If
End Sub
'------------------------------------------------------------
' Command2_Click
'
'------------------------------------------------------------
Private Sub Command2_Click()
    Call Cut_Update
End Sub

推荐答案

在两次调用之间,您唯一要做的事情是:

The only thing you do in between the calls in the form is:

[Forms]![Portal_02_Cut]![WO_Num].Value = ""

因此,尝试以下任一方法:

So, try with either:

[Forms]![Portal_02_Cut]![WO_Num].Text = ""

或:

[Forms]![Portal_02_Cut]![WO_Num].Value = Null

这篇关于MS Access VBA呼叫子项在第一次通过时有效,但在第二次不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆