I created a userForm to make possible to create a survey. It looks like that at the beginning:
Clicking the cross that is next to "Add answer" you can add more rows as it can be seen in this other image:
The problem that I have is that I have to add those small arrows that are next to the checkboxes in the new rows. Those are to move the answers up and down if the user need to change the position of them. So I have to add code to it to move them.
The creation of the elements that I need in each row is done in the following way:
Private Sub addAnswer_Click()
Image5.top = Image5.top + 21
CheckBox1.top = CheckBox1.top + 21
CheckBox2.top = CheckBox2.top + 21
Image7.height = Image7.height + 21
Image3.top = Image3.top + 21
Label1.top = Label1.top + 21
Label4.top = Label4.top + 21
Image2.top = Image2.top + 21
tablet.top = tablet.top + 21
chart.top = chart.top + 21
Label8.top = Label8.top + 21
Label9.top = Label9.top + 21
LabelOrizontal.top = LabelOrizontal.top + 21
LabelVertical.top = LabelVertical.top + 21
LabelNet.top = LabelNet.top + 21
LabelRound.top = LabelRound.top + 21
LabelPoints.top = LabelPoints.top + 21
Orizontal.top = Orizontal.top + 21
Vertical.top = Vertical.top + 21
Net.top = Net.top + 21
Points.top = Points.top + 21
Round.top = Round.top + 21
ExcelBox.top = ExcelBox.top + 21
OKButton.top = OKButton.top + 21
CancelButton.top = CancelButton.top + 21
'Me.MultiPage1.height = Me.MultiPage1.height + 21
Image1.height = Image1.height + 21
'height = 418 + 21 * (valueNum - 1)
If valueNum = 2 Then
With Me
'This will create a vertical scrollbar
.MultiPage1.Pages(0).ScrollBars = fmScrollBarsVertical
'Change the values of 2 as Per your requirements
'.ScrollHeight = .InsideHeight
'.ScrollWidth = .InsideWidth * 9
End With
End If
Me.MultiPage1.Pages(0).ScrollHeight = Me.MultiPage1.Pages(0).InsideHeight + 21 * (valueNum - 1)
valueNum = valueNum + 1
Set cCntrl = Me.MultiPage1.Pages(0).Controls.Add("Forms.TextBox.1", "textBox" & valueNum, True)
With cCntrl
.width = 156
.height = 18
.top = 108 + (valueNum - 1) * 21
.left = 48
.TabIndex = tabInd
.ZOrder (0)
End With
Set cCntrl1 = Me.MultiPage1.Pages(0).Controls.Add("Forms.TextBox.1", "AnsLabBox" & valueNum, True)
With cCntrl1
.width = 144
.height = 18
.top = 108 + (valueNum - 1) * 21
.left = 210
.TabIndex = tabInd + 1
.ZOrder (0)
End With
tabInd = tabInd + 3
Set cCntrl3 = Me.MultiPage1.Pages(0).Controls.Add("Forms.CheckBox.1", "open" & valueNum, True)
With cCntrl3
.left = 24
.width = 11
.height = 18
.BackColor = "&H8000000E"
.top = 108 + (valueNum - 1) * 21
.ZOrder (0)
End With
'''''''Here starts the important part for the question!!!
Set cCntrl3 = Me.MultiPage1.Pages(0).Controls.Add("Forms.Image.1", "down" & valueNum - 1, True)
With cCntrl3
.left = 12
.width = 12
.height = 6
.BackColor = "&H8000000E"
.top = 116 + (valueNum - 2) * 21
.Picture = LoadPicture(addInPath & "\fixContent\triangleDown.jpg")
.BorderStyle = fmBorderStyleNone
.PictureSizeMode = fmPictureSizeModeStretch
.ZOrder (0)
End With
With ActivePresentation.VBProject.VBComponents("surveyCreation").CodeModule
X = .CountOfLines
.InsertLines X + 1, "Private Sub down" & valueNum - 1 & "_Click()"
.InsertLines X + 2, "goDown " & valueNum - 1
.InsertLines X + 3, "End Sub"
End With
Set cCntrl3 = Me.MultiPage1.Pages(0).Controls.Add("Forms.Image.1", "up" & valueNum, True)
With cCntrl3
.left = 12
.width = 12
.height = 6
.BackColor = "&H8000000E"
.top = 111 + (valueNum - 1) * 21
.Picture = LoadPicture(addInPath & "\fixContent\triangleUp.jpg")
.BorderStyle = fmBorderStyleNone
.PictureSizeMode = fmPictureSizeModeStretch
.ZOrder (0)
End With
With ActivePresentation.VBProject.VBComponents("surveyCreation").CodeModule
X = .CountOfLines
.InsertLines X + 1, "Private Sub up" & valueNum & "_Click()"
.InsertLines X + 2, "goUp " & valueNum
.InsertLines X + 3, "End Sub"
End With
Set cCntrl3 = Me.MultiPage1.Pages(0).Controls.Add("Forms.Image.1", "delete" & valueNum, True)
With cCntrl3
.left = 480
.width = 12
.height = 12
.BackColor = "&H8000000E"
.top = 110 + (valueNum - 1) * 21
.Picture = LoadPicture(addInPath & "\fixContent\cross.jpg")
.BorderStyle = fmBorderStyleNone
.PictureSizeMode = fmPictureSizeModeStretch
.ZOrder (0)
End With
With ActivePresentation.VBProject.VBComponents("surveyCreation").CodeModule
X = .CountOfLines
.InsertLines X + 1, "Private Sub delete" & valueNum & "_Click()"
.InsertLines X + 2, "deleteRow " & valueNum
.InsertLines X + 3, "End Sub"
End With
If Not comboVisi Then
cCntrl2.Visible = False
End If
End Sub
So as you can see I create the elements and I also add some code (Click events) to the surveyCreation (witch is the userForm)
The deleteRow, goUp and goDown methods are also defined. But it is never entering in the click events. The first click events (the ones that are made for the arrows that appears in the first image) are defined previously and they are working but not the ones that I define using the code that I created. So can I make them work?