vba - 通过命令 VBA.Userform.Add("UF") 加载用户表单时重新初始化
问题描述
我陷入了VBA编码的问题。有两个名为“UsersForm”和“Registration”的用户表单。
在“UsersForm”中有一个名为 CreateProfile 的命令按钮,点击它应该会显示“Registration”表单。
为此目的,一个名为“ShowNextUF”的过程已编写在一个模块中,我在其中提供如下所示的参数:
Private Sub CreateProfile_Click() ' <----its an activex Command button of the userform "UsersForm"
Call ShowNextUF("Registration", Me, True)
End Sub
在模块中:
Sub ShowNextUF(ByVal NxtUF As String, ByVal PrevUF As Object, Optional ByVal UnLd As Boolean = False)
Dim nUF As Object
Set nUF = VBA.UserForms.Add(NxtUF)
If UnLd Then Unload PrevUF
nUF.Show
End Sub
现在的问题是:当我想检查用户窗体“注册”的文本框的值时,它工作正常..
Private Sub tbStdName_Change() '<---- A TextBox of "Registration" userform
StudenName = UCase(tbStdName.Value)
End Sub
但它没有(下);实际上在这种情况下,“注册”表单再次初始化。不知道为什么要重新初始化。
Private Sub tbStdName_Change()
StudenName = UCase(Registration.tbStdName.Value) '<---- Reinitilizing...
End Sub
当我在隐藏“注册”表单后调用该新用户表单时,我需要在另一个新用户表单中使用这个:UCase(Registration.tbStdName.Value)。我哪里错了?
解决方案
@Arno 范博文
感谢您提供的信息,它让我知道“.Add”将在 USerform 中添加新集合......刚刚尝试了这个想法,它得到了解决!
摆脱这种情况的方法是将参数作为对象而不是字符串传递......
Private Sub CreateProfile_Click()
Call ShowNextUF(Registration, Me, True)
End Sub
并在模块中:
Sub ShowNextUF(ByVal NxtUF As Object, ByVal PrevUF As Object, Optional ByVal UnLd As Boolean = False)
If UnLd Then Unload PrevUF
NxtUF.Show
End Sub
再次感谢...干杯!!!!
推荐阅读
- css - 如何为内联 svg 添加额外的外层空间?
- python - 在熊猫中对两个数据框进行分组并对匹配组执行操作的最佳方法
- javascript - Material-UI formControlLabel 整个标签是可点击的,只有文本应该是
- excel - IF ISNUMBER SEARCH - 区分相似文本
- java - 带有 JCheckBox 的 Swing TableHeader 在 Nimbus 中不起作用
- json - 弹性搜索不得使用无法正常工作的子句
- javascript - 为什么 XMLHttpRequest 变量变为“未定义”?
- mongodb - 如何在mongodb中嵌套查询?
- ajax - 加载 SecurityComponent 时的 CakePHP 3.8 问题
- async-await - 为什么我的 koa 应用程序在使用 Jest/Supertest 测试路由时会超时