Mon code a comme objectif de formatter les formulaires=20
d'une BDD automatiquement.
Le probl=E8me est qu'il ne fonctionne qu'une seule fois...
A partir du deuxi=E8me "run", certains champs sont=20
s=E9lectionn=E9s plusieurs fois et d'autres pas.=20
Incompr=E9hensible pour mon petit esprit!
Please help,
David
Public Sub pusDesignForm(frm As Form)
Dim ctrl As Control
Dim vstTmp As String
frm.AllowDesignChanges =3D False
If Left(frm.Caption, 3) =3D "frm" Then
frm.Caption =3D InputBox("CAPTION'S FORM: ", frm.Name)
End If
For Each ctrl In frm.Controls
vstTmp =3D ctrl.Name
Select Case ctrl.ControlType
Case acLabel
ctrl.BackStyle =3D 0
ctrl.SpecialEffect =3D 0
ctrl.ForeColor =3D 8388608
ctrl.FontWeight =3D 700
ctrl.FontUnderline =3D True
ctrl.FontSize =3D 8
ctrl.BorderWidth =3D 0
ctrl.BorderStyle =3D 0
ctrl.FontName =3D "MS Sans Serif"
ctrl.TextAlign =3D 2
If Left(vstTmp, 3) <> "lbl" Then
vstTmp =3D "lbl" & UCase(Left(vstTmp, 1)) &=20
Right(vstTmp, Len(vstTmp) - 1)
End If
If Right(vstTmp, 6) =3D "_label" Then
vstTmp =3D Left(vstTmp, Len(vstTmp) - 6)
End If
Case acTextBox
If Right(ctrl.Name, 6) =3D "UpdtDt" Or Right
(ctrl.Name, 5) =3D "LUpdt" Then
ctrl.Enabled =3D False
End If
If Left(vstTmp, 3) <> "txt" Then
vstTmp =3D "txt" & UCase(Left(vstTmp, 1)) &=20
Right(vstTmp, Len(vstTmp) - 1)
End If
ctrl.TextAlign =3D 1
If ctrl.StatusBarText =3D "" Or IsNull
(ctrl.StatusBarText) Then
ctrl.StatusBarText =3D InputBox("Status Bar=20
text: ", ctrl.Name)
End If
If ctrl.ControlTipText =3D "" Or IsNull
(ctrl.ControlTipText) Then
ctrl.ControlTipText =3D ctrl.StatusBarText
End If
Case acCheckBox
If Left(vstTmp, 3) <> "chk" Then
vstTmp =3D "chk" & UCase(Left(vstTmp, 1)) &=20
Right(vstTmp, Len(vstTmp) - 1)
End If
If ctrl.StatusBarText =3D "" Or IsNull
(ctrl.StatusBarText) Then
ctrl.StatusBarText =3D InputBox("Status Bar=20
text: ", ctrl.Name)
End If
If ctrl.ControlTipText =3D "" Or IsNull
(ctrl.ControlTipText) Then
ctrl.ControlTipText =3D ctrl.StatusBarText
End If
Case acCommandButton
ctrl.ForeColor =3D 8388608
If ctrl.Name =3D "cmdClose4" Then
ctrl.ControlTipText =3D "Close Form"
ctrl.StatusBarText =3D "Close Form"
ctrl.FontWeight =3D 700
End If
Case Else
End Select
Debug.Print vstTmp
ctrl.Name =3D vstTmp
Next ctrl
End Sub
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Gafish
Bonjour,
Pour qu'on puisse t'aider pour le mieux, mets ici le code qui te cause souci.
Arnaud
"David" a écrit dans le message news: 027c01c49c2f$a02546d0$ Bonsoir ou bonjour,
Mon code a comme objectif de formatter les formulaires d'une BDD automatiquement. Le problème est qu'il ne fonctionne qu'une seule fois... A partir du deuxième "run", certains champs sont sélectionnés plusieurs fois et d'autres pas. Incompréhensible pour mon petit esprit! Please help,
David
Public Sub pusDesignForm(frm As Form) Dim ctrl As Control Dim vstTmp As String frm.AllowDesignChanges = False If Left(frm.Caption, 3) = "frm" Then frm.Caption = InputBox("CAPTION'S FORM: ", frm.Name) End If For Each ctrl In frm.Controls vstTmp = ctrl.Name Select Case ctrl.ControlType Case acLabel ctrl.BackStyle = 0 ctrl.SpecialEffect = 0 ctrl.ForeColor = 8388608 ctrl.FontWeight = 700 ctrl.FontUnderline = True ctrl.FontSize = 8 ctrl.BorderWidth = 0 ctrl.BorderStyle = 0 ctrl.FontName = "MS Sans Serif" ctrl.TextAlign = 2 If Left(vstTmp, 3) <> "lbl" Then vstTmp = "lbl" & UCase(Left(vstTmp, 1)) & Right(vstTmp, Len(vstTmp) - 1) End If If Right(vstTmp, 6) = "_label" Then vstTmp = Left(vstTmp, Len(vstTmp) - 6) End If Case acTextBox If Right(ctrl.Name, 6) = "UpdtDt" Or Right (ctrl.Name, 5) = "LUpdt" Then ctrl.Enabled = False End If If Left(vstTmp, 3) <> "txt" Then vstTmp = "txt" & UCase(Left(vstTmp, 1)) & Right(vstTmp, Len(vstTmp) - 1) End If ctrl.TextAlign = 1 If ctrl.StatusBarText = "" Or IsNull (ctrl.StatusBarText) Then ctrl.StatusBarText = InputBox("Status Bar text: ", ctrl.Name) End If If ctrl.ControlTipText = "" Or IsNull (ctrl.ControlTipText) Then ctrl.ControlTipText = ctrl.StatusBarText End If Case acCheckBox If Left(vstTmp, 3) <> "chk" Then vstTmp = "chk" & UCase(Left(vstTmp, 1)) & Right(vstTmp, Len(vstTmp) - 1) End If If ctrl.StatusBarText = "" Or IsNull (ctrl.StatusBarText) Then ctrl.StatusBarText = InputBox("Status Bar text: ", ctrl.Name) End If If ctrl.ControlTipText = "" Or IsNull (ctrl.ControlTipText) Then ctrl.ControlTipText = ctrl.StatusBarText End If Case acCommandButton ctrl.ForeColor = 8388608 If ctrl.Name = "cmdClose4" Then ctrl.ControlTipText = "Close Form" ctrl.StatusBarText = "Close Form" ctrl.FontWeight = 700 End If Case Else End Select Debug.Print vstTmp ctrl.Name = vstTmp Next ctrl End Sub
Bonjour,
Pour qu'on puisse t'aider pour le mieux, mets ici le code qui te cause
souci.
Arnaud
"David" <anonymous@discussions.microsoft.com> a écrit dans le message news:
027c01c49c2f$a02546d0$a501280a@phx.gbl...
Bonsoir ou bonjour,
Mon code a comme objectif de formatter les formulaires
d'une BDD automatiquement.
Le problème est qu'il ne fonctionne qu'une seule fois...
A partir du deuxième "run", certains champs sont
sélectionnés plusieurs fois et d'autres pas.
Incompréhensible pour mon petit esprit!
Please help,
David
Public Sub pusDesignForm(frm As Form)
Dim ctrl As Control
Dim vstTmp As String
frm.AllowDesignChanges = False
If Left(frm.Caption, 3) = "frm" Then
frm.Caption = InputBox("CAPTION'S FORM: ", frm.Name)
End If
For Each ctrl In frm.Controls
vstTmp = ctrl.Name
Select Case ctrl.ControlType
Case acLabel
ctrl.BackStyle = 0
ctrl.SpecialEffect = 0
ctrl.ForeColor = 8388608
ctrl.FontWeight = 700
ctrl.FontUnderline = True
ctrl.FontSize = 8
ctrl.BorderWidth = 0
ctrl.BorderStyle = 0
ctrl.FontName = "MS Sans Serif"
ctrl.TextAlign = 2
If Left(vstTmp, 3) <> "lbl" Then
vstTmp = "lbl" & UCase(Left(vstTmp, 1)) &
Right(vstTmp, Len(vstTmp) - 1)
End If
If Right(vstTmp, 6) = "_label" Then
vstTmp = Left(vstTmp, Len(vstTmp) - 6)
End If
Case acTextBox
If Right(ctrl.Name, 6) = "UpdtDt" Or Right
(ctrl.Name, 5) = "LUpdt" Then
ctrl.Enabled = False
End If
If Left(vstTmp, 3) <> "txt" Then
vstTmp = "txt" & UCase(Left(vstTmp, 1)) &
Right(vstTmp, Len(vstTmp) - 1)
End If
ctrl.TextAlign = 1
If ctrl.StatusBarText = "" Or IsNull
(ctrl.StatusBarText) Then
ctrl.StatusBarText = InputBox("Status Bar
text: ", ctrl.Name)
End If
If ctrl.ControlTipText = "" Or IsNull
(ctrl.ControlTipText) Then
ctrl.ControlTipText = ctrl.StatusBarText
End If
Case acCheckBox
If Left(vstTmp, 3) <> "chk" Then
vstTmp = "chk" & UCase(Left(vstTmp, 1)) &
Right(vstTmp, Len(vstTmp) - 1)
End If
If ctrl.StatusBarText = "" Or IsNull
(ctrl.StatusBarText) Then
ctrl.StatusBarText = InputBox("Status Bar
text: ", ctrl.Name)
End If
If ctrl.ControlTipText = "" Or IsNull
(ctrl.ControlTipText) Then
ctrl.ControlTipText = ctrl.StatusBarText
End If
Case acCommandButton
ctrl.ForeColor = 8388608
If ctrl.Name = "cmdClose4" Then
ctrl.ControlTipText = "Close Form"
ctrl.StatusBarText = "Close Form"
ctrl.FontWeight = 700
End If
Case Else
End Select
Debug.Print vstTmp
ctrl.Name = vstTmp
Next ctrl
End Sub
Pour qu'on puisse t'aider pour le mieux, mets ici le code qui te cause souci.
Arnaud
"David" a écrit dans le message news: 027c01c49c2f$a02546d0$ Bonsoir ou bonjour,
Mon code a comme objectif de formatter les formulaires d'une BDD automatiquement. Le problème est qu'il ne fonctionne qu'une seule fois... A partir du deuxième "run", certains champs sont sélectionnés plusieurs fois et d'autres pas. Incompréhensible pour mon petit esprit! Please help,
David
Public Sub pusDesignForm(frm As Form) Dim ctrl As Control Dim vstTmp As String frm.AllowDesignChanges = False If Left(frm.Caption, 3) = "frm" Then frm.Caption = InputBox("CAPTION'S FORM: ", frm.Name) End If For Each ctrl In frm.Controls vstTmp = ctrl.Name Select Case ctrl.ControlType Case acLabel ctrl.BackStyle = 0 ctrl.SpecialEffect = 0 ctrl.ForeColor = 8388608 ctrl.FontWeight = 700 ctrl.FontUnderline = True ctrl.FontSize = 8 ctrl.BorderWidth = 0 ctrl.BorderStyle = 0 ctrl.FontName = "MS Sans Serif" ctrl.TextAlign = 2 If Left(vstTmp, 3) <> "lbl" Then vstTmp = "lbl" & UCase(Left(vstTmp, 1)) & Right(vstTmp, Len(vstTmp) - 1) End If If Right(vstTmp, 6) = "_label" Then vstTmp = Left(vstTmp, Len(vstTmp) - 6) End If Case acTextBox If Right(ctrl.Name, 6) = "UpdtDt" Or Right (ctrl.Name, 5) = "LUpdt" Then ctrl.Enabled = False End If If Left(vstTmp, 3) <> "txt" Then vstTmp = "txt" & UCase(Left(vstTmp, 1)) & Right(vstTmp, Len(vstTmp) - 1) End If ctrl.TextAlign = 1 If ctrl.StatusBarText = "" Or IsNull (ctrl.StatusBarText) Then ctrl.StatusBarText = InputBox("Status Bar text: ", ctrl.Name) End If If ctrl.ControlTipText = "" Or IsNull (ctrl.ControlTipText) Then ctrl.ControlTipText = ctrl.StatusBarText End If Case acCheckBox If Left(vstTmp, 3) <> "chk" Then vstTmp = "chk" & UCase(Left(vstTmp, 1)) & Right(vstTmp, Len(vstTmp) - 1) End If If ctrl.StatusBarText = "" Or IsNull (ctrl.StatusBarText) Then ctrl.StatusBarText = InputBox("Status Bar text: ", ctrl.Name) End If If ctrl.ControlTipText = "" Or IsNull (ctrl.ControlTipText) Then ctrl.ControlTipText = ctrl.StatusBarText End If Case acCommandButton ctrl.ForeColor = 8388608 If ctrl.Name = "cmdClose4" Then ctrl.ControlTipText = "Close Form" ctrl.StatusBarText = "Close Form" ctrl.FontWeight = 700 End If Case Else End Select Debug.Print vstTmp ctrl.Name = vstTmp Next ctrl End Sub
David
Je ne vois pas la partie du code qui pose problème. Je fais un parcours de tous les contrôles d'une forme et il en oublie certains et repasse plusieurs fois sur d'autres... Je ne comprends pas!!!
Merci de votre aide, David
Je ne vois pas la partie du code qui pose problème. Je
fais un parcours de tous les contrôles d'une forme et il
en oublie certains et repasse plusieurs fois sur
d'autres...
Je ne comprends pas!!!
Je ne vois pas la partie du code qui pose problème. Je fais un parcours de tous les contrôles d'une forme et il en oublie certains et repasse plusieurs fois sur d'autres... Je ne comprends pas!!!
Merci de votre aide, David
Gafish
Oui, mais mets ton code complet pour qu'on puisse regarder
"David" a écrit dans le message news: 144401c49c8e$130832d0$ Je ne vois pas la partie du code qui pose problème. Je fais un parcours de tous les contrôles d'une forme et il en oublie certains et repasse plusieurs fois sur d'autres... Je ne comprends pas!!!
Merci de votre aide, David
Oui, mais mets ton code complet pour qu'on puisse regarder
"David" <anonymous@discussions.microsoft.com> a écrit dans le message news:
144401c49c8e$130832d0$a301280a@phx.gbl...
Je ne vois pas la partie du code qui pose problème. Je
fais un parcours de tous les contrôles d'une forme et il
en oublie certains et repasse plusieurs fois sur
d'autres...
Je ne comprends pas!!!
Oui, mais mets ton code complet pour qu'on puisse regarder
"David" a écrit dans le message news: 144401c49c8e$130832d0$ Je ne vois pas la partie du code qui pose problème. Je fais un parcours de tous les contrôles d'une forme et il en oublie certains et repasse plusieurs fois sur d'autres... Je ne comprends pas!!!
Merci de votre aide, David
David
J'appelle via la fenêtre 'immediate'la sub dont le code est dans mon message initial par: pusDesignForm forms!frmMaForme. frmMaForme est en design view lors de l'appel.
Merci, David
J'appelle via la fenêtre 'immediate'la sub dont le code
est dans mon message initial par:
pusDesignForm forms!frmMaForme.
frmMaForme est en design view lors de l'appel.
J'appelle via la fenêtre 'immediate'la sub dont le code est dans mon message initial par: pusDesignForm forms!frmMaForme. frmMaForme est en design view lors de l'appel.
Merci, David
Eric
Bonjour David,
J'ai testé ta procédure et j'ai le même problème.
Je n'ai pas de réponse appropriée mais je pense que les modifs faites sur les contrôles doivent modifier leur rang dans la collection frm.Controls
J'ai même mis des sauvegardes après les modifs mais sans succès
J'ai ajouté 3 lignes au début de la proc qui m'affiche les controles du formulaire avec l'ordre initial avant ta boucle For Each ... contenant les les select case et les mêmes lignes à la fin de la procédure, derriere Next ctrl.
For Each ctrl In frm.Controls Debug.Print ctrl.Name, ctrl.ControlType Next ctrl
Le résultat à l'affichage dans le fenetre Execution de l'ordre des controles n'est plus le même.
au debut de la procédure: (Ordre de positionnement initial) txtToto 109 ' etiquette virée txtTata 109 ' idem txtTutu 109 ' idem chkBidon 106 lblÉtiquette7 100 'étiquette du checkbox cmdClose4 104
A la sortie de la boucle For Each ... Next ctrl txtTata 109 chkBidon 106 cmdClose4 104 txtTutu 109 txtToto 109 lblÉtiquette7 100
et l'affichage de ta variable vstTemp, dans ta boucle, me donne autre chose :
3 fois l'etiquette, 2 fois txtTutu et 1 fois txtToto
Je vais suivre la ficelle car la solution m'intéresse. A+ Eric
"David" écrivait news:07f101c49ca2 $4cf73180$:
J'appelle via la fenêtre 'immediate'la sub dont le code est dans mon message initial par: pusDesignForm forms!frmMaForme. frmMaForme est en design view lors de l'appel.
Merci, David
Bonjour David,
J'ai testé ta procédure et j'ai le même problème.
Je n'ai pas de réponse appropriée mais je pense que les modifs faites sur
les contrôles doivent modifier leur rang dans la collection frm.Controls
J'ai même mis des sauvegardes après les modifs mais sans succès
J'ai ajouté 3 lignes au début de la proc qui m'affiche les controles du
formulaire avec l'ordre initial avant ta boucle For Each ... contenant
les les select case et les mêmes lignes à la fin de la procédure,
derriere Next ctrl.
For Each ctrl In frm.Controls
Debug.Print ctrl.Name, ctrl.ControlType
Next ctrl
Le résultat à l'affichage dans le fenetre Execution de l'ordre des
controles n'est plus le même.
au debut de la procédure: (Ordre de positionnement initial)
txtToto 109 ' etiquette virée
txtTata 109 ' idem
txtTutu 109 ' idem
chkBidon 106
lblÉtiquette7 100 'étiquette du checkbox
cmdClose4 104
A la sortie de la boucle For Each ... Next ctrl
txtTata 109
chkBidon 106
cmdClose4 104
txtTutu 109
txtToto 109
lblÉtiquette7 100
et l'affichage de ta variable vstTemp, dans ta boucle, me donne autre
chose :
3 fois l'etiquette, 2 fois txtTutu et 1 fois txtToto
Je vais suivre la ficelle car la solution m'intéresse.
A+
Eric
J'appelle via la fenêtre 'immediate'la sub dont le code
est dans mon message initial par:
pusDesignForm forms!frmMaForme.
frmMaForme est en design view lors de l'appel.
Je n'ai pas de réponse appropriée mais je pense que les modifs faites sur les contrôles doivent modifier leur rang dans la collection frm.Controls
J'ai même mis des sauvegardes après les modifs mais sans succès
J'ai ajouté 3 lignes au début de la proc qui m'affiche les controles du formulaire avec l'ordre initial avant ta boucle For Each ... contenant les les select case et les mêmes lignes à la fin de la procédure, derriere Next ctrl.
For Each ctrl In frm.Controls Debug.Print ctrl.Name, ctrl.ControlType Next ctrl
Le résultat à l'affichage dans le fenetre Execution de l'ordre des controles n'est plus le même.
au debut de la procédure: (Ordre de positionnement initial) txtToto 109 ' etiquette virée txtTata 109 ' idem txtTutu 109 ' idem chkBidon 106 lblÉtiquette7 100 'étiquette du checkbox cmdClose4 104
A la sortie de la boucle For Each ... Next ctrl txtTata 109 chkBidon 106 cmdClose4 104 txtTutu 109 txtToto 109 lblÉtiquette7 100
et l'affichage de ta variable vstTemp, dans ta boucle, me donne autre chose :
3 fois l'etiquette, 2 fois txtTutu et 1 fois txtToto
Je vais suivre la ficelle car la solution m'intéresse. A+ Eric
"David" écrivait news:07f101c49ca2 $4cf73180$:
J'appelle via la fenêtre 'immediate'la sub dont le code est dans mon message initial par: pusDesignForm forms!frmMaForme. frmMaForme est en design view lors de l'appel.
Merci, David
?Lo»Paris?
David wrote:
Bonsoir ou bonjour,
Mon code a comme objectif de formatter les formulaires d'une BDD automatiquement. Le problème est qu'il ne fonctionne qu'une seule fois... A partir du deuxième "run", certains champs sont sélectionnés plusieurs fois et d'autres pas. Incompréhensible pour mon petit esprit! Please help,
David
Public Sub pusDesignForm(frm As Form) Dim ctrl As Control Dim vstTmp As String frm.AllowDesignChanges = False If Left(frm.Caption, 3) = "frm" Then frm.Caption = InputBox("CAPTION'S FORM: ", frm.Name) End If For Each ctrl In frm.Controls vstTmp = ctrl.Name Select Case ctrl.ControlType Case acLabel ctrl.BackStyle = 0 ctrl.SpecialEffect = 0 ctrl.ForeColor = 8388608 ctrl.FontWeight = 700 ctrl.FontUnderline = True ctrl.FontSize = 8 ctrl.BorderWidth = 0 ctrl.BorderStyle = 0 ctrl.FontName = "MS Sans Serif" ctrl.TextAlign = 2 If Left(vstTmp, 3) <> "lbl" Then vstTmp = "lbl" & UCase(Left(vstTmp, 1)) & Right(vstTmp, Len(vstTmp) - 1) End If If Right(vstTmp, 6) = "_label" Then vstTmp = Left(vstTmp, Len(vstTmp) - 6) End If Case acTextBox If Right(ctrl.Name, 6) = "UpdtDt" Or Right (ctrl.Name, 5) = "LUpdt" Then ctrl.Enabled = False End If If Left(vstTmp, 3) <> "txt" Then vstTmp = "txt" & UCase(Left(vstTmp, 1)) & Right(vstTmp, Len(vstTmp) - 1) End If ctrl.TextAlign = 1 If ctrl.StatusBarText = "" Or IsNull (ctrl.StatusBarText) Then ctrl.StatusBarText = InputBox("Status Bar text: ", ctrl.Name) End If If ctrl.ControlTipText = "" Or IsNull (ctrl.ControlTipText) Then ctrl.ControlTipText = ctrl.StatusBarText End If Case acCheckBox If Left(vstTmp, 3) <> "chk" Then vstTmp = "chk" & UCase(Left(vstTmp, 1)) & Right(vstTmp, Len(vstTmp) - 1) End If If ctrl.StatusBarText = "" Or IsNull (ctrl.StatusBarText) Then ctrl.StatusBarText = InputBox("Status Bar text: ", ctrl.Name) End If If ctrl.ControlTipText = "" Or IsNull (ctrl.ControlTipText) Then ctrl.ControlTipText = ctrl.StatusBarText End If Case acCommandButton ctrl.ForeColor = 8388608 If ctrl.Name = "cmdClose4" Then ctrl.ControlTipText = "Close Form" ctrl.StatusBarText = "Close Form" ctrl.FontWeight = 700 End If Case Else End Select Debug.Print vstTmp ctrl.Name = vstTmp Next ctrl End Sub
bonjour David,
Normal, si tu change le nom d'un ctr son n° d'index change, par exemple si tu as 3 ctr dans ton objet, tu dispose des controles :
form.controls(0) avec comme nom par exemple "ctrl1" form.controls(1) "ctrl2" form.controls(2) "ctrl3"
Si tu change le nom du control 0, il passe à la position 2 .... ce qui fait :
Et comme la boucle For Each se sert de l'Index (MonCtr.Index) des contrôles pour faire sa boucle... tu vois le problème...
La solution ?
A mon avis la plus simple c'est d'utiliser une table temporaire, tu stock dans celle-ci le nom original et le nouveau nom du ctr, ensuite à partir de cette table il est très simple de faire la modification du nom des contrôles.
Ha ! autre chose si le nom ne change pas, inutile de l'appliquer au contrôle : If (ctrl.Name <> vstTmp) Then ctrl.Name = vstTmp
Salutations
-- °Laurent°
David wrote:
Bonsoir ou bonjour,
Mon code a comme objectif de formatter les formulaires
d'une BDD automatiquement.
Le problème est qu'il ne fonctionne qu'une seule fois...
A partir du deuxième "run", certains champs sont
sélectionnés plusieurs fois et d'autres pas.
Incompréhensible pour mon petit esprit!
Please help,
David
Public Sub pusDesignForm(frm As Form)
Dim ctrl As Control
Dim vstTmp As String
frm.AllowDesignChanges = False
If Left(frm.Caption, 3) = "frm" Then
frm.Caption = InputBox("CAPTION'S FORM: ", frm.Name)
End If
For Each ctrl In frm.Controls
vstTmp = ctrl.Name
Select Case ctrl.ControlType
Case acLabel
ctrl.BackStyle = 0
ctrl.SpecialEffect = 0
ctrl.ForeColor = 8388608
ctrl.FontWeight = 700
ctrl.FontUnderline = True
ctrl.FontSize = 8
ctrl.BorderWidth = 0
ctrl.BorderStyle = 0
ctrl.FontName = "MS Sans Serif"
ctrl.TextAlign = 2
If Left(vstTmp, 3) <> "lbl" Then
vstTmp = "lbl" & UCase(Left(vstTmp, 1)) &
Right(vstTmp, Len(vstTmp) - 1)
End If
If Right(vstTmp, 6) = "_label" Then
vstTmp = Left(vstTmp, Len(vstTmp) - 6)
End If
Case acTextBox
If Right(ctrl.Name, 6) = "UpdtDt" Or Right
(ctrl.Name, 5) = "LUpdt" Then
ctrl.Enabled = False
End If
If Left(vstTmp, 3) <> "txt" Then
vstTmp = "txt" & UCase(Left(vstTmp, 1)) &
Right(vstTmp, Len(vstTmp) - 1)
End If
ctrl.TextAlign = 1
If ctrl.StatusBarText = "" Or IsNull
(ctrl.StatusBarText) Then
ctrl.StatusBarText = InputBox("Status Bar
text: ", ctrl.Name)
End If
If ctrl.ControlTipText = "" Or IsNull
(ctrl.ControlTipText) Then
ctrl.ControlTipText = ctrl.StatusBarText
End If
Case acCheckBox
If Left(vstTmp, 3) <> "chk" Then
vstTmp = "chk" & UCase(Left(vstTmp, 1)) &
Right(vstTmp, Len(vstTmp) - 1)
End If
If ctrl.StatusBarText = "" Or IsNull
(ctrl.StatusBarText) Then
ctrl.StatusBarText = InputBox("Status Bar
text: ", ctrl.Name)
End If
If ctrl.ControlTipText = "" Or IsNull
(ctrl.ControlTipText) Then
ctrl.ControlTipText = ctrl.StatusBarText
End If
Case acCommandButton
ctrl.ForeColor = 8388608
If ctrl.Name = "cmdClose4" Then
ctrl.ControlTipText = "Close Form"
ctrl.StatusBarText = "Close Form"
ctrl.FontWeight = 700
End If
Case Else
End Select
Debug.Print vstTmp
ctrl.Name = vstTmp
Next ctrl
End Sub
bonjour David,
Normal, si tu change le nom d'un ctr son n° d'index change, par exemple si
tu as 3 ctr dans ton objet, tu dispose des controles :
form.controls(0) avec comme nom par exemple "ctrl1"
form.controls(1) "ctrl2"
form.controls(2) "ctrl3"
Si tu change le nom du control 0, il passe à la position 2 .... ce qui fait
:
Et comme la boucle For Each se sert de l'Index (MonCtr.Index) des contrôles
pour faire sa boucle... tu vois le problème...
La solution ?
A mon avis la plus simple c'est d'utiliser une table temporaire, tu stock
dans celle-ci le nom original et le nouveau nom du ctr, ensuite à partir de
cette table il est très simple de faire la modification du nom des
contrôles.
Ha ! autre chose si le nom ne change pas, inutile de l'appliquer au contrôle
:
If (ctrl.Name <> vstTmp) Then ctrl.Name = vstTmp
Mon code a comme objectif de formatter les formulaires d'une BDD automatiquement. Le problème est qu'il ne fonctionne qu'une seule fois... A partir du deuxième "run", certains champs sont sélectionnés plusieurs fois et d'autres pas. Incompréhensible pour mon petit esprit! Please help,
David
Public Sub pusDesignForm(frm As Form) Dim ctrl As Control Dim vstTmp As String frm.AllowDesignChanges = False If Left(frm.Caption, 3) = "frm" Then frm.Caption = InputBox("CAPTION'S FORM: ", frm.Name) End If For Each ctrl In frm.Controls vstTmp = ctrl.Name Select Case ctrl.ControlType Case acLabel ctrl.BackStyle = 0 ctrl.SpecialEffect = 0 ctrl.ForeColor = 8388608 ctrl.FontWeight = 700 ctrl.FontUnderline = True ctrl.FontSize = 8 ctrl.BorderWidth = 0 ctrl.BorderStyle = 0 ctrl.FontName = "MS Sans Serif" ctrl.TextAlign = 2 If Left(vstTmp, 3) <> "lbl" Then vstTmp = "lbl" & UCase(Left(vstTmp, 1)) & Right(vstTmp, Len(vstTmp) - 1) End If If Right(vstTmp, 6) = "_label" Then vstTmp = Left(vstTmp, Len(vstTmp) - 6) End If Case acTextBox If Right(ctrl.Name, 6) = "UpdtDt" Or Right (ctrl.Name, 5) = "LUpdt" Then ctrl.Enabled = False End If If Left(vstTmp, 3) <> "txt" Then vstTmp = "txt" & UCase(Left(vstTmp, 1)) & Right(vstTmp, Len(vstTmp) - 1) End If ctrl.TextAlign = 1 If ctrl.StatusBarText = "" Or IsNull (ctrl.StatusBarText) Then ctrl.StatusBarText = InputBox("Status Bar text: ", ctrl.Name) End If If ctrl.ControlTipText = "" Or IsNull (ctrl.ControlTipText) Then ctrl.ControlTipText = ctrl.StatusBarText End If Case acCheckBox If Left(vstTmp, 3) <> "chk" Then vstTmp = "chk" & UCase(Left(vstTmp, 1)) & Right(vstTmp, Len(vstTmp) - 1) End If If ctrl.StatusBarText = "" Or IsNull (ctrl.StatusBarText) Then ctrl.StatusBarText = InputBox("Status Bar text: ", ctrl.Name) End If If ctrl.ControlTipText = "" Or IsNull (ctrl.ControlTipText) Then ctrl.ControlTipText = ctrl.StatusBarText End If Case acCommandButton ctrl.ForeColor = 8388608 If ctrl.Name = "cmdClose4" Then ctrl.ControlTipText = "Close Form" ctrl.StatusBarText = "Close Form" ctrl.FontWeight = 700 End If Case Else End Select Debug.Print vstTmp ctrl.Name = vstTmp Next ctrl End Sub
bonjour David,
Normal, si tu change le nom d'un ctr son n° d'index change, par exemple si tu as 3 ctr dans ton objet, tu dispose des controles :
form.controls(0) avec comme nom par exemple "ctrl1" form.controls(1) "ctrl2" form.controls(2) "ctrl3"
Si tu change le nom du control 0, il passe à la position 2 .... ce qui fait :
Et comme la boucle For Each se sert de l'Index (MonCtr.Index) des contrôles pour faire sa boucle... tu vois le problème...
La solution ?
A mon avis la plus simple c'est d'utiliser une table temporaire, tu stock dans celle-ci le nom original et le nouveau nom du ctr, ensuite à partir de cette table il est très simple de faire la modification du nom des contrôles.
Ha ! autre chose si le nom ne change pas, inutile de l'appliquer au contrôle : If (ctrl.Name <> vstTmp) Then ctrl.Name = vstTmp
Salutations
-- °Laurent°
Bonjour Laurent,
Merci pour cette explication. Comment expliquer néanmoins que cela fonctionne la première fois?
Cordialement, David
-----Message d'origine----- David wrote:
Bonsoir ou bonjour,
Mon code a comme objectif de formatter les formulaires d'une BDD automatiquement. Le problème est qu'il ne fonctionne qu'une seule fois... A partir du deuxième "run", certains champs sont sélectionnés plusieurs fois et d'autres pas. Incompréhensible pour mon petit esprit! Please help,
David
Public Sub pusDesignForm(frm As Form) Dim ctrl As Control Dim vstTmp As String frm.AllowDesignChanges = False If Left(frm.Caption, 3) = "frm" Then frm.Caption = InputBox("CAPTION'S FORM: ", frm.Name) End If For Each ctrl In frm.Controls vstTmp = ctrl.Name Select Case ctrl.ControlType Case acLabel ctrl.BackStyle = 0 ctrl.SpecialEffect = 0 ctrl.ForeColor = 8388608 ctrl.FontWeight = 700 ctrl.FontUnderline = True ctrl.FontSize = 8 ctrl.BorderWidth = 0 ctrl.BorderStyle = 0 ctrl.FontName = "MS Sans Serif" ctrl.TextAlign = 2 If Left(vstTmp, 3) <> "lbl" Then vstTmp = "lbl" & UCase(Left(vstTmp, 1)) &
Right(vstTmp, Len(vstTmp) - 1) End If If Right(vstTmp, 6) = "_label" Then vstTmp = Left(vstTmp, Len(vstTmp) - 6) End If Case acTextBox If Right(ctrl.Name, 6) = "UpdtDt" Or Right (ctrl.Name, 5) = "LUpdt" Then ctrl.Enabled = False End If If Left(vstTmp, 3) <> "txt" Then vstTmp = "txt" & UCase(Left(vstTmp, 1)) &
Right(vstTmp, Len(vstTmp) - 1) End If ctrl.TextAlign = 1 If ctrl.StatusBarText = "" Or IsNull (ctrl.StatusBarText) Then ctrl.StatusBarText = InputBox("Status Bar
text: ", ctrl.Name) End If If ctrl.ControlTipText = "" Or IsNull (ctrl.ControlTipText) Then ctrl.ControlTipText = ctrl.StatusBarText End If Case acCheckBox If Left(vstTmp, 3) <> "chk" Then vstTmp = "chk" & UCase(Left(vstTmp, 1)) &
Right(vstTmp, Len(vstTmp) - 1) End If If ctrl.StatusBarText = "" Or IsNull (ctrl.StatusBarText) Then ctrl.StatusBarText = InputBox("Status Bar
text: ", ctrl.Name) End If If ctrl.ControlTipText = "" Or IsNull (ctrl.ControlTipText) Then ctrl.ControlTipText = ctrl.StatusBarText End If Case acCommandButton ctrl.ForeColor = 8388608 If ctrl.Name = "cmdClose4" Then ctrl.ControlTipText = "Close Form" ctrl.StatusBarText = "Close Form" ctrl.FontWeight = 700 End If Case Else End Select Debug.Print vstTmp ctrl.Name = vstTmp Next ctrl End Sub
bonjour David,
Normal, si tu change le nom d'un ctr son n° d'index change, par exemple si
tu as 3 ctr dans ton objet, tu dispose des controles :
form.controls(0) avec comme nom par exemple "ctrl1" form.controls(1) "ctrl2" form.controls(2) "ctrl3"
Si tu change le nom du control 0, il passe à la position 2 .... ce qui fait
Et comme la boucle For Each se sert de l'Index (MonCtr.Index) des contrôles
pour faire sa boucle... tu vois le problème...
La solution ?
A mon avis la plus simple c'est d'utiliser une table temporaire, tu stock
dans celle-ci le nom original et le nouveau nom du ctr, ensuite à partir de
cette table il est très simple de faire la modification du nom des
contrôles.
Ha ! autre chose si le nom ne change pas, inutile de l'appliquer au contrôle
: If (ctrl.Name <> vstTmp) Then ctrl.Name = vstTmp
Salutations
-- °Laurent°
.
Bonjour Laurent,
Merci pour cette explication.
Comment expliquer néanmoins que cela fonctionne la
première fois?
Cordialement,
David
-----Message d'origine-----
David wrote:
Bonsoir ou bonjour,
Mon code a comme objectif de formatter les formulaires
d'une BDD automatiquement.
Le problème est qu'il ne fonctionne qu'une seule fois...
A partir du deuxième "run", certains champs sont
sélectionnés plusieurs fois et d'autres pas.
Incompréhensible pour mon petit esprit!
Please help,
David
Public Sub pusDesignForm(frm As Form)
Dim ctrl As Control
Dim vstTmp As String
frm.AllowDesignChanges = False
If Left(frm.Caption, 3) = "frm" Then
frm.Caption = InputBox("CAPTION'S FORM: ", frm.Name)
End If
For Each ctrl In frm.Controls
vstTmp = ctrl.Name
Select Case ctrl.ControlType
Case acLabel
ctrl.BackStyle = 0
ctrl.SpecialEffect = 0
ctrl.ForeColor = 8388608
ctrl.FontWeight = 700
ctrl.FontUnderline = True
ctrl.FontSize = 8
ctrl.BorderWidth = 0
ctrl.BorderStyle = 0
ctrl.FontName = "MS Sans Serif"
ctrl.TextAlign = 2
If Left(vstTmp, 3) <> "lbl" Then
vstTmp = "lbl" & UCase(Left(vstTmp, 1))
&
Right(vstTmp, Len(vstTmp) - 1)
End If
If Right(vstTmp, 6) = "_label" Then
vstTmp = Left(vstTmp, Len(vstTmp) - 6)
End If
Case acTextBox
If Right(ctrl.Name, 6) = "UpdtDt" Or Right
(ctrl.Name, 5) = "LUpdt" Then
ctrl.Enabled = False
End If
If Left(vstTmp, 3) <> "txt" Then
vstTmp = "txt" & UCase(Left(vstTmp, 1))
&
Right(vstTmp, Len(vstTmp) - 1)
End If
ctrl.TextAlign = 1
If ctrl.StatusBarText = "" Or IsNull
(ctrl.StatusBarText) Then
ctrl.StatusBarText = InputBox("Status
Bar
text: ", ctrl.Name)
End If
If ctrl.ControlTipText = "" Or IsNull
(ctrl.ControlTipText) Then
ctrl.ControlTipText = ctrl.StatusBarText
End If
Case acCheckBox
If Left(vstTmp, 3) <> "chk" Then
vstTmp = "chk" & UCase(Left(vstTmp, 1))
&
Right(vstTmp, Len(vstTmp) - 1)
End If
If ctrl.StatusBarText = "" Or IsNull
(ctrl.StatusBarText) Then
ctrl.StatusBarText = InputBox("Status
Bar
text: ", ctrl.Name)
End If
If ctrl.ControlTipText = "" Or IsNull
(ctrl.ControlTipText) Then
ctrl.ControlTipText = ctrl.StatusBarText
End If
Case acCommandButton
ctrl.ForeColor = 8388608
If ctrl.Name = "cmdClose4" Then
ctrl.ControlTipText = "Close Form"
ctrl.StatusBarText = "Close Form"
ctrl.FontWeight = 700
End If
Case Else
End Select
Debug.Print vstTmp
ctrl.Name = vstTmp
Next ctrl
End Sub
bonjour David,
Normal, si tu change le nom d'un ctr son n° d'index
change, par exemple si
tu as 3 ctr dans ton objet, tu dispose des controles :
form.controls(0) avec comme nom par exemple "ctrl1"
form.controls(1) "ctrl2"
form.controls(2) "ctrl3"
Si tu change le nom du control 0, il passe à la position
2 .... ce qui fait
Merci pour cette explication. Comment expliquer néanmoins que cela fonctionne la première fois?
Cordialement, David
-----Message d'origine----- David wrote:
Bonsoir ou bonjour,
Mon code a comme objectif de formatter les formulaires d'une BDD automatiquement. Le problème est qu'il ne fonctionne qu'une seule fois... A partir du deuxième "run", certains champs sont sélectionnés plusieurs fois et d'autres pas. Incompréhensible pour mon petit esprit! Please help,
David
Public Sub pusDesignForm(frm As Form) Dim ctrl As Control Dim vstTmp As String frm.AllowDesignChanges = False If Left(frm.Caption, 3) = "frm" Then frm.Caption = InputBox("CAPTION'S FORM: ", frm.Name) End If For Each ctrl In frm.Controls vstTmp = ctrl.Name Select Case ctrl.ControlType Case acLabel ctrl.BackStyle = 0 ctrl.SpecialEffect = 0 ctrl.ForeColor = 8388608 ctrl.FontWeight = 700 ctrl.FontUnderline = True ctrl.FontSize = 8 ctrl.BorderWidth = 0 ctrl.BorderStyle = 0 ctrl.FontName = "MS Sans Serif" ctrl.TextAlign = 2 If Left(vstTmp, 3) <> "lbl" Then vstTmp = "lbl" & UCase(Left(vstTmp, 1)) &
Right(vstTmp, Len(vstTmp) - 1) End If If Right(vstTmp, 6) = "_label" Then vstTmp = Left(vstTmp, Len(vstTmp) - 6) End If Case acTextBox If Right(ctrl.Name, 6) = "UpdtDt" Or Right (ctrl.Name, 5) = "LUpdt" Then ctrl.Enabled = False End If If Left(vstTmp, 3) <> "txt" Then vstTmp = "txt" & UCase(Left(vstTmp, 1)) &
Right(vstTmp, Len(vstTmp) - 1) End If ctrl.TextAlign = 1 If ctrl.StatusBarText = "" Or IsNull (ctrl.StatusBarText) Then ctrl.StatusBarText = InputBox("Status Bar
text: ", ctrl.Name) End If If ctrl.ControlTipText = "" Or IsNull (ctrl.ControlTipText) Then ctrl.ControlTipText = ctrl.StatusBarText End If Case acCheckBox If Left(vstTmp, 3) <> "chk" Then vstTmp = "chk" & UCase(Left(vstTmp, 1)) &
Right(vstTmp, Len(vstTmp) - 1) End If If ctrl.StatusBarText = "" Or IsNull (ctrl.StatusBarText) Then ctrl.StatusBarText = InputBox("Status Bar
text: ", ctrl.Name) End If If ctrl.ControlTipText = "" Or IsNull (ctrl.ControlTipText) Then ctrl.ControlTipText = ctrl.StatusBarText End If Case acCommandButton ctrl.ForeColor = 8388608 If ctrl.Name = "cmdClose4" Then ctrl.ControlTipText = "Close Form" ctrl.StatusBarText = "Close Form" ctrl.FontWeight = 700 End If Case Else End Select Debug.Print vstTmp ctrl.Name = vstTmp Next ctrl End Sub
bonjour David,
Normal, si tu change le nom d'un ctr son n° d'index change, par exemple si
tu as 3 ctr dans ton objet, tu dispose des controles :
form.controls(0) avec comme nom par exemple "ctrl1" form.controls(1) "ctrl2" form.controls(2) "ctrl3"
Si tu change le nom du control 0, il passe à la position 2 .... ce qui fait
Et comme la boucle For Each se sert de l'Index (MonCtr.Index) des contrôles
pour faire sa boucle... tu vois le problème...
La solution ?
A mon avis la plus simple c'est d'utiliser une table temporaire, tu stock
dans celle-ci le nom original et le nouveau nom du ctr, ensuite à partir de
cette table il est très simple de faire la modification du nom des
contrôles.
Ha ! autre chose si le nom ne change pas, inutile de l'appliquer au contrôle
: If (ctrl.Name <> vstTmp) Then ctrl.Name = vstTmp
Salutations
-- °Laurent°
.
?Lo»Paris?
wrote:
Bonjour Laurent,
Merci pour cette explication. Comment expliquer néanmoins que cela fonctionne la première fois?
Cordialement, David
Salut David,
J'ai pas vraiment détaillé ton code, mais à mon avis c'est à cause du "ctrl.Name = vstTmp" qui ne tient pas compte si le nom du ctr à changer ou non, fait un test et dit moi si je me trouve.
Salutations
-- °Laurent°
anonymous@discussions.microsoft.com wrote:
Bonjour Laurent,
Merci pour cette explication.
Comment expliquer néanmoins que cela fonctionne la
première fois?
Cordialement,
David
Salut David,
J'ai pas vraiment détaillé ton code, mais à mon avis c'est à cause du
"ctrl.Name = vstTmp" qui ne tient pas compte si le nom du ctr à changer ou
non, fait un test et dit moi si je me trouve.
Merci pour cette explication. Comment expliquer néanmoins que cela fonctionne la première fois?
Cordialement, David
Salut David,
J'ai pas vraiment détaillé ton code, mais à mon avis c'est à cause du "ctrl.Name = vstTmp" qui ne tient pas compte si le nom du ctr à changer ou non, fait un test et dit moi si je me trouve.