OVH Cloud OVH Cloud

function remplir tous les controles

5 réponses
Avatar
John Smith
Salut,

Je fais une appli genre interface pour une base de donnée. J'ai plusieurs
form avec différent controle(textbox combobox maskedit...). Je veux faire
une fonction pour m'assurer que tous les controles soient remplis par
l'utilisateur.

Je sais pas trop comment m'y prendre.

Est-ce que vous avez des idées ou avez -vous déjà écrit ce genre de fonction

Merci a tous

5 réponses

Avatar
Clive Lumb
Essayer ceci (à mettre dans une procédure au niveau du form à vérifier)

Dim MyControl As Control
For Each MyControl In Me.Controls
Select Case TypeName(MyControl)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
If MyControl.Text = "" Then
MsgBox "Merci de renseigner " & MyControl.Name
End If
Case Else
End Select
Next



"John Smith" a écrit dans le message de
news:Gszpf.1134$
Salut,

Je fais une appli genre interface pour une base de donnée. J'ai plusieurs
form avec différent controle(textbox combobox maskedit...). Je veux faire
une fonction pour m'assurer que tous les controles soient remplis par
l'utilisateur.

Je sais pas trop comment m'y prendre.

Est-ce que vous avez des idées ou avez -vous déjà écrit ce genre de


fonction

Merci a tous




Avatar
John Smith
Salut,

J'ai modifié un peu le code pour avoir un sub facilement utilisable

Je voudrais avoir votre avis...
Public allok as boolean


Sub allok1(exclus As Collection)
Dim MyControl As control
Dim y As Integer
allok = True
For Each MyControl In Me.Controls
Select Case TypeName(MyControl)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
y = 1
Do
If MyControl.Text = "" And MyControl.Name <> exclus.item(y) Then
allok = False
MsgBox "Il manque des renseignements.", vbInformation

Exit Sub
End If
y = y + 1

If exclus.Count <= y Then Exit Do
Loop
Case Else
End Select
Next
End Sub

Private Sub Command1_Click()
Dim strexclus As New Collection
strexclus.add "Text7"
allok1 strexclus
If allok = False Then
Exit Sub
End If
end sub
"Clive Lumb" wrote in message
news:
Essayer ceci (à mettre dans une procédure au niveau du form à vérifier)

Dim MyControl As Control
For Each MyControl In Me.Controls
Select Case TypeName(MyControl)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
If MyControl.Text = "" Then
MsgBox "Merci de renseigner " & MyControl.Name
End If
Case Else
End Select
Next



"John Smith" a écrit dans le message de
news:Gszpf.1134$
Salut,

Je fais une appli genre interface pour une base de donnée. J'ai plusieurs
form avec différent controle(textbox combobox maskedit...). Je veux faire
une fonction pour m'assurer que tous les controles soient remplis par
l'utilisateur.

Je sais pas trop comment m'y prendre.

Est-ce que vous avez des idées ou avez -vous déjà écrit ce genre de


fonction

Merci a tous








Avatar
John Smith
Re amélioré

Private Sub Command1_Click()
Dim strexclus As New Collection
strexclus.Add "Text2"
strexclus.Add "Text4"
Debug.Print allok(strexclus, Form1)
End Sub

Function allok(exclus As Collection, frm As Form) As Boolean
Dim MyControl As Control
Dim y As Integer
Dim exclusyes As Boolean
allok = True
For Each MyControl In frm.Controls
Select Case TypeName(MyControl)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
y = 1
exclusyes = False
Do
Debug.Print MyControl.Name & exclus.Item(y)
If MyControl.Name = exclus.Item(y) Then
exclusyes = True
Exit Do
End If
y = y + 1
Loop Until exclus.Count < y
Debug.Print MyControl.Name & exclusyes
If MyControl.Text = "" And exclusyes = False Then
allok = False
MsgBox "Il manque des renseignements.", vbInformation
Exit Function
End If

Case Else
End Select
Next
End Function

"John Smith" wrote in message
news:CnCpf.797$%
Salut,

J'ai modifié un peu le code pour avoir un sub facilement utilisable

Je voudrais avoir votre avis...
Public allok as boolean


Sub allok1(exclus As Collection)
Dim MyControl As control
Dim y As Integer
allok = True
For Each MyControl In Me.Controls
Select Case TypeName(MyControl)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
y = 1
Do
If MyControl.Text = "" And MyControl.Name <> exclus.item(y) Then
allok = False
MsgBox "Il manque des renseignements.", vbInformation

Exit Sub
End If
y = y + 1

If exclus.Count <= y Then Exit Do
Loop
Case Else
End Select
Next
End Sub

Private Sub Command1_Click()
Dim strexclus As New Collection
strexclus.add "Text7"
allok1 strexclus
If allok = False Then
Exit Sub
End If
end sub
"Clive Lumb" wrote in message
news:
Essayer ceci (à mettre dans une procédure au niveau du form à vérifier)

Dim MyControl As Control
For Each MyControl In Me.Controls
Select Case TypeName(MyControl)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
If MyControl.Text = "" Then
MsgBox "Merci de renseigner " & MyControl.Name
End If
Case Else
End Select
Next



"John Smith" a écrit dans le message de
news:Gszpf.1134$
Salut,

Je fais une appli genre interface pour une base de donnée. J'ai
plusieurs
form avec différent controle(textbox combobox maskedit...). Je veux
faire
une fonction pour m'assurer que tous les controles soient remplis par
l'utilisateur.

Je sais pas trop comment m'y prendre.

Est-ce que vous avez des idées ou avez -vous déjà écrit ce genre de


fonction

Merci a tous












Avatar
Clive Lumb
Très bien.
Mais essayes ceci

Dans le Form_Load
Me.txtAgeCap.Tag = "l'age du Capitaine"
Me.cmbSexeMat.Tag = "le sexe du matelot"
Me.rchedNomCuistot = "le nom du cuisinier"

Dans AllOK
MsgBox "Vous n'avez pas fourni " & MyControl.Tag, vbInformation


Clive

John Smith wrote:
Re amélioré

Private Sub Command1_Click()
Dim strexclus As New Collection
strexclus.Add "Text2"
strexclus.Add "Text4"
Debug.Print allok(strexclus, Form1)
End Sub

Function allok(exclus As Collection, frm As Form) As Boolean
Dim MyControl As Control
Dim y As Integer
Dim exclusyes As Boolean
allok = True
For Each MyControl In frm.Controls
Select Case TypeName(MyControl)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
y = 1
exclusyes = False
Do
Debug.Print MyControl.Name & exclus.Item(y)
If MyControl.Name = exclus.Item(y) Then
exclusyes = True
Exit Do
End If
y = y + 1
Loop Until exclus.Count < y
Debug.Print MyControl.Name & exclusyes
If MyControl.Text = "" And exclusyes = False Then
allok = False
MsgBox "Il manque des renseignements.", vbInformation
Exit Function
End If

Case Else
End Select
Next
End Function

"John Smith" wrote in message
news:CnCpf.797$%
Salut,

J'ai modifié un peu le code pour avoir un sub facilement utilisable

Je voudrais avoir votre avis...
Public allok as boolean


Sub allok1(exclus As Collection)
Dim MyControl As control
Dim y As Integer
allok = True
For Each MyControl In Me.Controls
Select Case TypeName(MyControl)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
y = 1
Do
If MyControl.Text = "" And MyControl.Name <> exclus.item(y) Then
allok = False
MsgBox "Il manque des renseignements.", vbInformation

Exit Sub
End If
y = y + 1

If exclus.Count <= y Then Exit Do
Loop
Case Else
End Select
Next
End Sub

Private Sub Command1_Click()
Dim strexclus As New Collection
strexclus.add "Text7"
allok1 strexclus
If allok = False Then
Exit Sub
End If
end sub
"Clive Lumb" wrote in message
news:
Essayer ceci (à mettre dans une procédure au niveau du form à
vérifier)

Dim MyControl As Control
For Each MyControl In Me.Controls
Select Case TypeName(MyControl)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
If MyControl.Text = "" Then
MsgBox "Merci de renseigner " & MyControl.Name
End If
Case Else
End Select
Next



"John Smith" a écrit dans le message de
news:Gszpf.1134$
Salut,

Je fais une appli genre interface pour une base de donnée. J'ai
plusieurs
form avec différent controle(textbox combobox maskedit...). Je veux
faire
une fonction pour m'assurer que tous les controles soient remplis
par l'utilisateur.

Je sais pas trop comment m'y prendre.

Est-ce que vous avez des idées ou avez -vous déjà écrit ce genre
de fonction

Merci a tous








Avatar
John Smith
salut,

PRend en charge les control array et le message précédent...
Private Sub Command1_Click()
Dim strexclus As New Collection
strexclus.Add "Text1(0)"
MsgBox allok(strexclus, Form1)
End Sub

Function allok(exclus As Collection, frm As Form) As Boolean
Dim mycontrol As Control
Dim y As Integer
Dim exclusyes As Boolean
allok = True
For Each mycontrol In frm.Controls
Select Case TypeName(mycontrol)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
y = 1
exclusyes = False
If isControlArray(frm, mycontrol) = True Then

Do
If mycontrol.Name & "(" & mycontrol.Index & ")" = exclus.Item(y) Then

exclusyes = True
Exit Do
End If
y = y + 1
Loop Until exclus.Count < y
Debug.Print exclusyes & " " & mycontrol.Name & " " & mycontrol.Index
If mycontrol.Text = "" And exclusyes = False Then
allok = False
MsgBox "Vous n'avez pas fourni " & MyControl.Tag, vbInformation

Exit Function
End If



Else

Do
If mycontrol.Name = exclus.Item(y) Then
exclusyes = True
Exit Do
End If
y = y + 1
Loop Until exclus.Count < y
If mycontrol.Text = "" And exclusyes = False Then
allok = False
MsgBox "Vous n'avez pas fourni " & MyControl.Tag, vbInformation

Exit Function
End If
End If
Case Else
End Select
Next
End Function
Public Function isControlArray(MyForm As Form, mycontrol As Control) As
Boolean


'BGS 8/1/1999 Added this function to det
' ermin if a Control is part of
'a control array or not. I had to do thi
' s because VB does not have a
'function that figures this out IsArray

' does not work on Control Arrays

On Error GoTo EH
Dim MyCount As Integer
Dim CheckMyControl As Control



For Each CheckMyControl In MyForm.Controls


If CheckMyControl.Name = mycontrol.Name Then
MyCount = MyCount + 1
End If

Next


isControlArray = MyCount - 1
Exit Function
EH:
MsgBox Err.Description & "in Form " & MyForm.Name, ,
"isControlArray"
End Function
"Clive Lumb" wrote in message
news:
Très bien.
Mais essayes ceci

Dans le Form_Load
Me.txtAgeCap.Tag = "l'age du Capitaine"
Me.cmbSexeMat.Tag = "le sexe du matelot"
Me.rchedNomCuistot = "le nom du cuisinier"

Dans AllOK
MsgBox "Vous n'avez pas fourni " & MyControl.Tag, vbInformation


Clive

John Smith wrote:
Re amélioré

Private Sub Command1_Click()
Dim strexclus As New Collection
strexclus.Add "Text2"
strexclus.Add "Text4"
Debug.Print allok(strexclus, Form1)
End Sub

Function allok(exclus As Collection, frm As Form) As Boolean
Dim MyControl As Control
Dim y As Integer
Dim exclusyes As Boolean
allok = True
For Each MyControl In frm.Controls
Select Case TypeName(MyControl)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
y = 1
exclusyes = False
Do
Debug.Print MyControl.Name & exclus.Item(y)
If MyControl.Name = exclus.Item(y) Then
exclusyes = True
Exit Do
End If
y = y + 1
Loop Until exclus.Count < y
Debug.Print MyControl.Name & exclusyes
If MyControl.Text = "" And exclusyes = False Then
allok = False
MsgBox "Il manque des renseignements.", vbInformation
Exit Function
End If

Case Else
End Select
Next
End Function

"John Smith" wrote in message
news:CnCpf.797$%
Salut,

J'ai modifié un peu le code pour avoir un sub facilement utilisable

Je voudrais avoir votre avis...
Public allok as boolean


Sub allok1(exclus As Collection)
Dim MyControl As control
Dim y As Integer
allok = True
For Each MyControl In Me.Controls
Select Case TypeName(MyControl)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
y = 1
Do
If MyControl.Text = "" And MyControl.Name <> exclus.item(y) Then
allok = False
MsgBox "Il manque des renseignements.", vbInformation

Exit Sub
End If
y = y + 1

If exclus.Count <= y Then Exit Do
Loop
Case Else
End Select
Next
End Sub

Private Sub Command1_Click()
Dim strexclus As New Collection
strexclus.add "Text7"
allok1 strexclus
If allok = False Then
Exit Sub
End If
end sub
"Clive Lumb" wrote in message
news:
Essayer ceci (à mettre dans une procédure au niveau du form à
vérifier)

Dim MyControl As Control
For Each MyControl In Me.Controls
Select Case TypeName(MyControl)
Case Is = "MaskEdBox", "TextBox", "ComboBox"
If MyControl.Text = "" Then
MsgBox "Merci de renseigner " & MyControl.Name
End If
Case Else
End Select
Next



"John Smith" a écrit dans le message de
news:Gszpf.1134$
Salut,

Je fais une appli genre interface pour une base de donnée. J'ai
plusieurs
form avec différent controle(textbox combobox maskedit...). Je veux
faire
une fonction pour m'assurer que tous les controles soient remplis
par l'utilisateur.

Je sais pas trop comment m'y prendre.

Est-ce que vous avez des idées ou avez -vous déjà écrit ce genre
de fonction

Merci a tous