I'm a bit of a newbie with Excel VBA but by reading this forum and scouring the internet for example code, I have managed to put together a multipage userform to collect user inputted data and transfer it to a worksheet. The worksheet data is then auto transferred to a Word template to form a report.
So, Userform1 has multiple named textboxes, eg Textbox71obs, Textbox72obs etc. Each of these textboxes has a default value of "None".
If a user clicks into any of these textboxes, if the textbox value is "None", then that value disappears and the user can enter their own text. If it's anything other than "None" then the user can still enter the textbox to amend but the original text remains, as planned.
The following code, which I cobbled together from various internet searches works fine for any textbox on the form, except for the textboxes which are contained within a frame.
VBA for the Userform1
Dim TextBoxes() As New Class17
Private Sub UserForm_Initialize()
Dim Counter As Integer, Obj As Control
For Each Obj In Me.Controls
If TypeOf Obj Is MSForms.TextBox Then
Counter = Counter + 1
ReDim Preserve TextBoxes(1 To Counter)
Set TextBoxes(Counter).TextBoxEvents = Obj
End If
Next
Set Obj = Nothing
End Sub
Code for Class Module
Public WithEvents TextBoxEvents As MSForms.TextBox
Private Sub TextBoxEvents_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If UserForm1.ActiveControl.Value = "None" Then
UserForm1.ActiveControl.Value = ""
End If
End Sub
In the cases of textboxes within a frame, I get a run time error 438 - object doesnt support this property or method at this line of the class module:
If UserForm1.ActiveControl.Value = "None" Then UserForm1.ActiveControl.Value = ""
I'm guessing that its something to do with the 'ActiveControl.value' not relating to a textbox in a frame, but i havent been able to source a solution to rework this line of the code, as yet.
Any help appreciated!
Thanks
Bookmarks