Re: Assign click functionality to dynamically created textboxes?




Well, found another way around the problem through trial and error in
case anyone has a simalr problem and a search turns up this thread:

Used:


Code:
--------------------
Function GetTextValue()

Dim Code as String

'insert code that controls the building of the userform. In my case, 2 command buttons and a dynamic number of textboxes

Code = ""
Dim tlRow As Long
Dim M As Long
Dim Part1 As String
Dim Part2 As String
Dim Part3 As String
With Worksheets("hidden1")
tlRow = .Cells(Rows.Count, 26).End(xlUp).Row 'where i get the values for the textboxes

' Define 3 string variables and create code blocks that will coorespond to each dynamically created textbox

For M = 1 To tlRow

Part1 = "Sub Textbox" & M & "_dblclick(ByVal Cancel as MSForms.ReturnBoolean)"
Part2 = " Textbox" & M & " = calendar1"
Part3 = "End Sub"

Code = Code & Part1 & vbCrLf
Code = Code & Part2 & vbCrLf
Code = Code & Part3 & vbCrLf

Next M

End With

' Code for CommandButton1
Code = Code & "Sub CommandButton1_Click()" & vbCrLf
Code = Code & "Unload Me" & vbCrLf
Code = Code & "Call Canceled" & vbCrLf
Code = Code & "End Sub" & vbCrLf

'Code for CommandButton2
Code = Code & "Sub CommandButton2_Click()" & vbCrLf
Code = Code & "Unload Me" & vbCrLf
Code = Code & "Call OK" & vbCrLf
Code = Code & "End Sub" & vbCrLf

End Function


--------------------


When the function is called, a runtime-genreated form is generated.
The code of that useform is generated by the code = code "" statements.
To create dynamic code for the useform, I put the For loop inside the
codeblock for the useform that looped for each instance of a textbox.


--
Ouka
------------------------------------------------------------------------
Ouka's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=23988
View this thread: http://www.excelforum.com/showthread.php?threadid=398001

.



Relevant Pages

  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Auto Write Name and Merge across
    ... Dim Sheetname01 As String ... Dim WeekName01 As String ...
    (microsoft.public.excel.misc)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Help answer these 70-310 questions
    ... One argument is the string ... Dim output As New StringBuilder ... EmployeeLocations. ... You create a strongly named serviced component. ...
    (microsoft.public.cert.exam.mcsd)