【问题标题】:TxtBox setfocus does not focus correctlyTxtBox setfocus 没有正确聚焦
【发布时间】:2018-04-13 00:06:43
【问题描述】:

我有一个用户名文本框。格式是 firstname.lastname,我正在尝试检查该框是否有“。”在名称中验证字符串。消息框工作正常,但无论何时单击“确定”,它仍会转到下一个文本框,而不是返回 txt_Name 来编辑名称条目。

Private Sub txt_Name_AfterUpdate()

    Dim username As String

    username = UCase(Me.txt_Name.Value)
    Me.txt_Name.Value = username


    If InStr(1, txt_Name.Text, ".", vbTextCompare) > 0 Then
        Me.cb_Shift.SetFocus
    Else
        MsgBox ("Please use the following format:" & vbCrLf & _
               "FirstName.LastName")
        Me.txt_Name.SetFocus
    End If

End Sub

【问题讨论】:

    标签: ms-access ms-access-2016


    【解决方案1】:

    对于此类验证,请使用BeforeUpdate 事件,如果值无效,请将 Cancel 变量设置为 True。在这种情况下,您将不需要 SetFocus

    【讨论】:

    • 我没有cancel变量,请解释一下
    • 每个文本框都有BefeoreUpdate事件,Cancel变量是该事件的参数,创建该事件时自动生成。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    • 1970-01-01
    • 2011-01-21
    • 2019-09-10
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    相关资源
    最近更新 更多