Hello All,
I have created a blank user form. Dynamically I have added Text Box, Label, Check Box and command Button to it. I have been able to handle the even generated while command button is clicked.Upon clicking the command button, user form will be unloaded. However I am trying to validate the value entered into Text Box and verify check box is selected and this is where I cannot access them using following code. Please help:
Please help
Thanks
Angsuman
I have created a blank user form. Dynamically I have added Text Box, Label, Check Box and command Button to it. I have been able to handle the even generated while command button is clicked.Upon clicking the command button, user form will be unloaded. However I am trying to validate the value entered into Text Box and verify check box is selected and this is where I cannot access them using following code. Please help:
Code:
=========================
Code In Unload
=========================
Dim clsCommand () As New clsCommandClass
CcCount = 2
k = 0
Public Sub UserForm_Initialize()
For i = 1 To CcCount
Set CcB = CcDataCollect.Controls.Add("Forms.TextBox.1", "CcBox" & i)
k = k + 1
ReDim Preserve clsCommand(1 To k)
Set clsCommand(k).clsCmdGroup = CcB
Set CcB = CcDataCollect.Controls.Add("Forms.TextBox.1", "CcdBox" & i)
k = k + 1
ReDim Preserve clsCommand(1 To k)
Set clsCommand(k).clsCmdGroup = CcB
Set CcBt = CcDataCollect.Controls.Add("Forms.CheckBox.1", "CcCheckBoxA" & i, True)
k = k + 1
ReDim Preserve clsCommand(1 To k)
Set clsCommand(k).clsCmdGroup = CcBt
Set CcBt = CcDataCollect.Controls.Add("Forms.CheckBox.1", "CcCheckBoxB" & i, True)
k = k + 1
ReDim Preserve clsCommand(1 To k)
Set clsCommand(k).clsCmdGroup = CcBt
Next i
Set clcb = CcDataCollect.Controls.Add("Forms.CommandButton.1", "CloseComButton")
k = k + 1
ReDim Preserve clsCommand(1 To k)
Set clsCommand(k).clsCmdGroup = clcb
End Sub
=========================
Code In Class clsCommand
=========================
Option Explicit
Public WithEvents clsCmdGroup As MSForms.CommandButton
Private Sub clsCmdGroup_Click()
<----- This is where I want to validate the value and if text box value is incorrect or is
empty the focus
should go back to Text Box
Unload CcDataCollect
End Sub
Please help
Thanks
Angsuman