重新加载表单时如何在文本框中保留值 [英] How to retain the value in textbox when the form gets reloaded

查看:63
本文介绍了重新加载表单时如何在文本框中保留值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的vba宏应用程序,由2个文本框和命令按钮组成.想法是用户需要在文本框中输入数字值,然后单击按钮将其禁用,以使他们无法更改该值.重新加载表单后,数值会丢失,我必须重新输入另一个值.

I have a very simple vba macro app consisting of 2 textboxs and command button. The idea is the user needs to input numeric value in textboxes and then clicks the button to disable it so they can't change the value. When the form gets reloaded, the numeric value gets lost and I have to re-input another value.

我想要的是重新加载表单后,数值将保持不变.

What I want is when the form reloaded,the numeric value will stay.

Private Sub btnLock_Click()

txtApple.Enabled = False
txtBanana.Enabled = False

End Sub

图片

Image

[

推荐答案

您需要记住,本质上讲,您拥有工作簿本身可以使用的数据库.

You need to remember that you have, what is essentially, a database at your disposal with the workbook itself.

我的建议是,当用户添加值并单击按钮时,将该值插入到工作表中(您可能需要用它来保护,隐藏等……或与此无关),然后获取该值.再次打开表单时,从工作表中返回值.

My suggestion is, when the user adds the value and clicks the button, insert that value into a worksheet (with which you may need to secure, hide, etc. ... or not for that matter) and then get that value back from the worksheet when the form is opened again.

从本质上讲,您只需要将值放在可以再次出现的表单中即可.如果您不喜欢工作表方法,那么总会有一个数据库,工作站上的文件,内存等.

You essentially just need to put the value somewhere that you can get it from again when the form reappears. If you don't like the worksheet approach then there's always a database, file on the workstation, memory, etc.

类似这样的事情...

Something like this ...

Private Sub btnLockBox_Click()
    Sheet1.Range("A1") = txtNumber.Text
    txtNumber.Enabled = False
End Sub

Private Sub UserForm_Initialize()
    txtNumber.Text = Sheet1.Range("A1")

    If txtNumber.Text <> "" Then
        txtNumber.Enabled = False
    End If
End Sub

我希望我已经正确理解了您的要求,希望这种方法能有所帮助.

I hope I've understood your requirement properly and I hope that approach helps.

这篇关于重新加载表单时如何在文本框中保留值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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