如何传递光标并将焦点设置为VBA中的Userform文本框? [英] How can I pass cursor and set focus on a Userform textbox in VBA?

查看:1147
本文介绍了如何传递光标并将焦点设置为VBA中的Userform文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的程序中,我收到此错误:运行时错误'-2147467259(80004005)':未指定的错误。通过突出显示此代码: txtStartDate.SetFocus 在此行中:如果txtStartDate.Text =然后txtStartDate.SetFocus / p>

In below program, I receive this error: Run-time error '-2147467259(80004005)': Unspecified error. by highlight this code: txtStartDate.SetFocus in this line: If txtStartDate.Text = "" Then txtStartDate.SetFocus

Private Sub txtTimeUnit_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If IsError(Application.Match(txtTimeUnit.Text, Range("intTable[Units]"), 0)) Then
    lblStatusBar = "Please correct value."
    Cancel = True
    Exit Sub
End If

lblStatusBar = vbNullString

Range("CToDate").Value = txtTimeUnit.Text

If txtStartDate.Text = "" Then txtStartDate.SetFocus
If txtEndDate.Text = "" Then txtEndDate.SetFocus

End Sub

任何人都可以帮助我这个错误,并将文本框焦点(Cursor)传递给另一个文本框?

Can anyone help me about this error and passing text box focus (Cursor) to another text box?

推荐答案

替换

If txtStartDate.Text = "" Then txtStartDate.SetFocus

If txtStartDate.Text = "" Then
    txtStartDate.SetFocus
    Exit Sub
End If

这篇关于如何传递光标并将焦点设置为VBA中的Userform文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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