Compléments pour Microsoft Access

http://access.fr.free.fr/

Vérifier l'existence d'un contrôle dans un formulaire (Formulaire)

Description 

Cette fonction permet de vérifier l'existence d'un contrôle dans un formulaire précis.

 
Synthaxe 

ControlExist(strForm, strControl)

La synthaxe de la fonction ControlExist comprend les éléments suivants :

ElémentsDescription

strForm

Expression de chaîne correspondant au nom du formulaire où l'on souhaite rechercher le contrôle.
strControlExpression de chaîne correspondant au nom du contrôl que l'on souhaite vérifier.
 
Exemple 

Aucun exemple disponible pour le moment.

 
Code de la fonction 


 Function ControlExist(strForm As String, strControl As String) As Boolean

'Vérifie l'existant d'un control sur un formulaire
On Error GoTo ErrControlExist
Dim frm As Form
Dim ctl As Control
DoCmd.Echo False
DoCmd.OpenForm strForm, acDesign
Set frm = Forms(strForm)
For Each ctl In frm.Controls
    If ctl.Name = strControl Then
        ControlExist = True
        Exit For
    End If
Next
DoCmd.Close acForm, strForm, acSaveNo
DoCmd.Echo True
Exit Function
ErrControlExist:
    DoCmd.Close acForm, strForm, acSaveNo
    DoCmd.Echo True
    MsgBox Err.Number & vbCrLf & vbCrLf & Err.Description, vbCritical

End Function