文本框事件 - 试图退出表单或擦除触发事件的字段 [英] Textbox Events - Stuck trying to exit form or wipe field on triggering event

查看:76
本文介绍了文本框事件 - 试图退出表单或擦除触发事件的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在采购订单编号的表单上有一个文本框。


一旦PO输入,就会发生以下情况之一。


1)数据库中尚不存在采购订单,继续收集与新采购订单相关的剩余数据。


2)采购订单中存在采购订单但已关闭。询问是否要重新开启并关注用户请求。


3)PO存在于数据库中并且已打开。 通知用户输入新号码或允许退出数据条目。



第3项是难以理解的。 我已经尝试过BeforeUpdate,AfterUpdate,Exit和LostFocus事件。 两个关键点是我希望文本框清空,以便用户输入新的数字或使表格关闭。


代码示例:


Private Sub PONum_BeforeUpdate(取消为整数)



Dim db As dao.Database

Dim rst_POHead as dao.Recordset

Dim Response As Integer

Dim Style As String



设置db = CurrentDb

设置rst_POHead = db.OpenRecordset(" tblPoHead",dbOpenDynaset)

Style = vbYesNo + vbDefaultButton1



rst_POHead.FindFirst" PONum = "" &安培;我!PONum& "'"
$


如果rst_POHead.NoMatch = True则为
   我!PONum.BorderColor = RGB(0,255,0)
$
否则

   如果rst_POHead!Complete = True则为
       我!PONum.BorderColor = RGB(255,0,0)

       响应= MsgBox("PO已存在但已关闭。 您是否要重新打开PO?",样式,"PO存在")

      ;  如果Response = vbYes则为
           取消=错误

           使用rst_POHead

                .Edit

                    !完成=错误

                .Update

           结束与$
          我!PONum.BorderColor = RGB(0,255,0)

       否则为
           取消=正确
           我!PONum.Undo

           我!cmdChangePONum.Visible = False

           我!cmdReset.Visible = False

       结束如果是
   否则

        MsgBox"PO已在系统中打开。输入其他号码。"

       我!PONum.BorderColor = RGB(166,166,166)

        DoCmd.CancelEvent

       我!PONum.Undo

   结束如果

结束如果



rst_POHead.Close

设置rst_POHead = Nothing



db。关闭

设置db =无什么b
$ b结束次



感谢任何输入,


Lance

解决方案

< blockquote>

Hi Lance,


在代码的所有其他部分中,您使用了Cancel = True;但是在PO存在和打开的部分,您使用了DoCmd.CancelEvent。


您也可以尝试使用Cancel = True。


只是一个想法......


I have a textbox on a form for a Purchase order number.

Once the PO is enter one of the following is to happen.

1) The PO doesn't yet exist in the DB, continue to gather remaining data related to new PO.

2) The PO exists in the DB but is already closed. Ask if wanting to reopen and follow users request.

3) The PO exists in the DB and is open.  Inform the user to enter a new number or allow to quit the data entry.

It is item 3 that is stumping me.  I have tried the BeforeUpdate, AfterUpdate, Exit and LostFocus events.  The two sticking points are that I would like the textbox to be emptied for the user to enter a new number or have the form close.

Example of code:

Private Sub PONum_BeforeUpdate(Cancel As Integer)

Dim db As dao.Database
Dim rst_POHead As dao.Recordset
Dim Response As Integer
Dim Style As String

Set db = CurrentDb
Set rst_POHead = db.OpenRecordset("tblPoHead", dbOpenDynaset)
Style = vbYesNo + vbDefaultButton1

rst_POHead.FindFirst "PONum = '" & Me!PONum & "'"

If rst_POHead.NoMatch = True Then
    Me!PONum.BorderColor = RGB(0, 255, 0)
Else
    If rst_POHead!Complete = True Then
        Me!PONum.BorderColor = RGB(255, 0, 0)
        Response = MsgBox("PO Already Exists but is closed.  Do you wish to Reopen PO?", Style, "PO Exists")
        If Response = vbYes Then
            Cancel = False
            With rst_POHead
                .Edit
                    !Complete = False
                .Update
            End With
            Me!PONum.BorderColor = RGB(0, 255, 0)
        Else
            Cancel = True
            Me!PONum.Undo
            Me!cmdChangePONum.Visible = False
            Me!cmdReset.Visible = False
        End If
    Else
        MsgBox "PO is already Open in the system. Enter a different number."
        Me!PONum.BorderColor = RGB(166, 166, 166)
        DoCmd.CancelEvent
        Me!PONum.Undo
    End If
End If

rst_POHead.Close
Set rst_POHead = Nothing

db.Close
Set db = Nothing

End Sub

Thanks for any input,

Lance

解决方案

Hi Lance,

In all the other parts of your code, you used Cancel = True; but in the part where the PO exists and open, you used DoCmd.CancelEvent.

You might try using Cancel = True there as well.

Just a thought...


这篇关于文本框事件 - 试图退出表单或擦除触发事件的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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