Bonjour ,
Selon le nombre de champs contenu dans la table de la BD choisie , je désire créer dynamiquement des controls pour tout les champs.. seulement j'ai un petit soucis :s
Voici une partie de mon code :
et
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 For i = 0 To Form1.resu.Fields.Count - 1 Set o = Form1.resu.Fields(i) Set c = Form2.Controls.Add("VB.label", "lbl" & Format(i)) c.FontBold = True c.Top = (i * 300) + 50 c.Left = 100 c.Height = 250 c.Caption = o.Name & "(" & typeofField(o) & ")" If typeofField(o) = "B" Then Set t = Me.Controls.Add("VB.checkBox", o.Name) Else: Set t = Me.Controls.Add("VB.TextBox", o.Name) End If t.Visible = True t.Top = (i * 300) + 20 t.Left = 2000 t.Height = 250 If (o.Attributes And adFidIsNullable) Then t.BackColor = RGB(224, 224, 224) End If If o.Attributes = 16 Then t.TabStop = False t.Locked = True t.BackColor = RGB(32, 224, 224) End If If typeofField(o) = "T" Then t.MaxLength = o.DefinedSize t.Width = DefinedSize * 1300 Else t.Width = 1000 End If On Error GoTo 0 If typeofField(o) = "N" Or typeofField(o) = "C" Then t.Alignment = 1 Else t.Alignment = 0 End If Next i End Sub
Comme résultat , j'obtiens , pour chaque champs , un txtfield vide de 1cm sans labels
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 Function typeofField(f As ADODB.Field) As String Select Case f.Type Case adBigInt typeofField = "N" Case adBoolean typeofField = "B" Case adCurrency typeofField = "C" Case adDate, adBDate, adDBTime, adDBTimeStamp typeofField = "D" Case adGUID typeofField = "G" Case adLongVarChar typeofField = "M" Case Else typeofField = "T" End Select End Function
Pourriez-vous m'éclairer svp
Partager