简体   繁体   English

VBA Excel:用户表单文本框未在用户表单框架中正确更新

[英]VBA Excel: Userform textboxes not updating properly in userform frames

Im trying to create a system within a VBA textbox that modifies the input so that the rest of the scripts can work properly.我试图在 VBA 文本框中创建一个系统,该文本框会修改输入,以便脚本的 rest 可以正常工作。 These textboxes along with other options are in frames that can be opened and closed.这些文本框以及其他选项位于可以打开和关闭的框架中。 Done so to keep the form readable for other people.这样做是为了保持表单对其他人的可读性。 I know it can be done by editing the string soley in code(and have done that to keep working on the project) but I thought it would be neat for ppl to see the edits the code makes visually.我知道这可以通过在代码中编辑字符串 soley 来完成(并且已经这样做以继续在项目上工作),但我认为 ppl 可以直观地看到代码所做的编辑。

However these updates are inconsistent at best.然而,这些更新充其量是不一致的。 I have 2 textboxes that edit themselves with identical lines of code and their both set to update themselves once the textbox has been exited.我有 2 个文本框,它们使用相同的代码行进行编辑,并且它们都设置为在退出文本框后自行更新。 One only updates if something within the frame that its in gets clicked on again and the other doesnt update at all no matter what click in within its frame or outside.仅当再次单击其所在框架内的某些内容时,一个才会更新,而另一个则根本不更新,无论在其框架内或外部单击什么。

Ideally The moment a textbox gets edited and something else gets clicked on the textbox updates but Im not having any luck with my attempts to fix them.理想情况下,当文本框被编辑并且在文本框更新上单击其他内容时,我尝试修复它们时没有任何运气。

Update Only updates itself if something else like another checkbox in the frame is clicked or selected and it will also then work when clicking outside of the frame.更新仅当单击或选中框架中的另一个复选框等其他内容时才更新自身,并且在框架外单击时它也将起作用。 Anyone know why?有谁知道为什么?

Code for both两者的代码

Private Sub Pathbox_Change()

End Sub

Private Sub Pathbox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim sDir As String
sDir = S5Int.Pathbox.Text
If Right(sDir, 1) <> "\" Then
     S5Int.Pathbox.Text = sDir & "\"
End If

End Sub

The exact same code for poth except the name of the procedure.除了过程的名称外,与 poth 完全相同的代码。 Frames are also exact same except for their names.除了名称之外,框架也完全相同。 In the form they look something like this:在形式中,它们看起来像这样:

Form with textboxes带有文本框的表单
带有相关文本框的表格

Settings of the elements are also identical元素的设置也相同
框架设置 文本框的设置

Found a solution last week;上周找到了解决方案;
I have just put the trigger of updating on the form itself whenever the form itself is clicked it runs through checks to see what needs to be updated and updates;每当单击表单本身时,我刚刚将更新触发器放在表单本身上,它会运行检查以查看需要更新和更新的内容; Its a bit crude but it works quite well.它有点粗糙,但效果很好。 This solution wont work if something else other than the form is clicked but that didnt work either for Textbox1_Exit(etc).如果单击表单以外的其他内容,则此解决方案将不起作用,但对于 Textbox1_Exit(etc) 也不起作用。 Since it only updates the form when the form is in the forefront.因为它只在表单位于最前面时更新表单。
It is Also a bit wasteful of cycles as it runs every single time anything on the form is clicked too but as long as the checks are efficient it should be good enough.这也有点浪费循环,因为它每次单击表单上的任何内容时都会运行,但只要检查有效,它就足够了。

I will keep working on a better solution however when I have time, maybe see if I can get exiting from the frame working like FaneDuru said but something else on the form seems to be blocking that solution for now.我将继续研究更好的解决方案,但是当我有时间时,也许看看我是否可以像 FaneDuru 所说的那样退出框架工作,但表格上的其他东西似乎暂时阻止了该解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM