kapela2017
New Member
- Joined
- Oct 16, 2022
- Messages
- 34
- Office Version
- 365
- Platform
- Windows
Greetings colleagues Currently and started working with class modules
in Vba, Please elaborate this small example to try to explain as best as possible and
in the simplest way, you see I'm trying to store a variable in a
textbox, (Textbox1) and store it in a Class Module ( C_ct) to be able to
call it at any time and from another instance, in this example I call it
through CommandButton2 but when I delete the information from the textbox it is deleted
also the variable, that is, a blank msgbox is displayed, I have the impression that I need
something at the class module level and in the Initialize event of Userform1, thank you very much
for your contributions I will be attentive to your contributions
[/CODE]
in Vba, Please elaborate this small example to try to explain as best as possible and
in the simplest way, you see I'm trying to store a variable in a
textbox, (Textbox1) and store it in a Class Module ( C_ct) to be able to
call it at any time and from another instance, in this example I call it
through CommandButton2 but when I delete the information from the textbox it is deleted
also the variable, that is, a blank msgbox is displayed, I have the impression that I need
something at the class module level and in the Initialize event of Userform1, thank you very much
for your contributions I will be attentive to your contributions
VBA Code:
[CODE=vba]
'in the textbox
Private Sub TextBox1_Change()
miClase.nuevoValor = TextBox1.Value
End Sub
'in the commandbutton1
Private Sub CommandButton1_Click()
Dim miClase As New C_ct
miClase.miValor = TextBox1.Value
MsgBox miClase.miValor
End Sub
'In the class module I declare it
'as follows
Private miNuevoValor As String
Public Property Let nuevoValor(ByVal nuevoValor As String)
miNuevoValor = nuevoValor
End Property
Public Property Get miValor() As String
miValor = miNuevoValor
End Property
Private Sub Class_Initialize()
miNuevoValor = UserForm1.TextBox1.Value
End Sub
'And to call it from another instance I do it like this
Private Sub CommandButton2_Click()
Dim miClase As New C_ct
MsgBox miClase.miValor
End Sub
[/CODE]