How to name dynamics labels?

zbang

New Member
Joined
Sep 8, 2014
Messages
1
Hello,

I have the below code.
There is a userform with multipages.
I noticed that the lables and textboxes are not defined individualy.
How can I give certain namees in label and how can I control certain textboxes? Also, how can I replace a textbox with a combobox?

Thank you.



Option Base 1
Option Explicit
Dim tabel As ListObject
Dim rand_c As Long
Dim a_controls(16, 10) As Control


Function Verifica_Nume(ByVal nume As String) As Integer
If tabel.ListColumns(1).Range.Find(nume) Is Nothing Then
Verifica_Nume = 0
Else
Verifica_Nume = tabel.ListColumns(1).Range.Find(nume).Row
End If
End Function


Sub Adauga_Controale()
Dim i, j As Integer
Dim k As Control
'Adauga TextBox-uri
For j = 1 To 10
For i = 1 To 16
Set a_controls(i, j) = MultiPage1.Pages(j - 1).Controls.Add("Forms.TextBox.1", "TextBox_" & Trim(Str(j)) & "_" & Trim(Str(i)), True)
a_controls(i, j).Width = 150
a_controls(i, j).Height = 18
a_controls(i, j).Left = 48 + Int(i / 9) * 192
a_controls(i, j).Top = 6 + ((i - 1) Mod 8) * 24
Next i
Next j
'Adauga Label-uri
For j = 1 To 10
For i = 1 To 16
Set k = MultiPage1.Pages(j - 1).Controls.Add("Forms.Label.1", "Label_" & Trim(Str(j)) & "_" & Trim(Str(i)), True)
k.Width = 38
k.Height = 10
k.Left = 6 + Int(i / 9) * 194
k.Top = 9 + ((i - 1) Mod 8) * 24
k.Caption = tabel.ListColumns((j - 1) * 16 + i + 1).Name & ":"
Next i
Next j
End Sub
Sub Seteaza_Controale()
Dim i, j As Integer
For j = 1 To 10
For i = 1 To 16
a_controls(i, j).ControlSource = tabel.ListColumns((j - 1) * 16 + i + 1).Range(rand_c).Address
Next i
Next j
End Sub


Private Sub CmdAdauga_Click()
If Len(Trim(TextNume.Text)) > 0 Then
Dim rand As Integer
If Verifica_Nume(TextNume.Text) = 0 Then
'Determina primul rand gol din tabel
If Len(tabel.ListColumns(1).Range(tabel.ListColumns(1).Range.Rows.Count).Value) = 0 Then
rand = 0
Else
rand = 1
End If
tabel.ListColumns(1).Range(tabel.ListColumns(1).Range.Rows.Count + rand).Value = Trim(TextNume.Text)
ListaNume.RowSource = "Clienti[Nume]"
TextNume.Text = ""
ListaNume.ListIndex = ListaNume.ListCount - 1
MultiPage1.Enabled = True
rand_c = ListaNume.ListCount
Else
MsgBox "Nume client existent. Selectati din lista si editati campurile"
End If
Else
MsgBox "Lipsa nume client"
End If
End Sub


Private Sub CmdIesire_Click()
Set tabel = Nothing
Dim i, j As Integer
For j = 1 To 10
For i = 1 To 16
Set a_controls(i, j) = Nothing
Next i
Next j
End
End Sub


Private Sub ListaNume_Change()
rand_c = tabel.ListColumns(1).Range.Find(ListaNume.List(ListaNume.ListIndex, 0)).Row - tabel.ListColumns(1).Range.Row + 1
Call Seteaza_Controale
End Sub




Private Sub UserForm_Initialize()
Set tabel = Worksheets("Sheet1").ListObjects("Clienti")
Call Adauga_Controale
If ListaNume.ListCount = 0 Then
rand_c = 0
MultiPage1.Enabled = False
MsgBox "Nu exista clienti in baza de date, folositi optiunea 'Adauga Nume Client'"
TextNume.SetFocus
Else
If ListaNume.ListCount = 1 And Len(ListaNume.List(ListaNume.ListCount - 1, 0)) = 0 Then
rand_c = 0
MultiPage1.Enabled = False
MsgBox "Nu exista clienti in baza de date, folositi optiunea 'Adauga Nume Client'"
TextNume.SetFocus
Else
ListaNume.ListIndex = 0
rand_c = 1
MultiPage1.Enabled = True
End If
End If
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,214,806
Messages
6,121,672
Members
449,045
Latest member
Marcus05

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top