Access-o-Mania

Access-Forum (Deutsch/German) => Access Programmierung => Thema gestartet von: Frank77 am November 16, 2014, 15:38:38

Titel: Felder auf inhalt prüfen mit Array
Beitrag von: Frank77 am November 16, 2014, 15:38:38
Hallo!

Ich würde gerne Felder in einem Formular  mit der Prozedur cmd_Speichern_Click() durchlaufen
Aber bei der Zeile passiert nichts
If Nz(ctrlName, "") = "" Then Prüfen = False


Private Sub cmd_Speichern_Click()
    Dim ctl As Control
    Dim A As Variant
    Dim L As Variant
    Dim i As Integer
    Dim ctrlName As String
    Dim Prüfen As Boolean
    Prüfen = True

    A = Array("Rahmen_Personendaten", "cmd_Speichern", "cbo_AnredeID", "txt_Nachname", "txt_Vorname", "cbo_Geschlecht", _
              "txt_Geburtsname", "cbo_Familienstand", "txt_Geburtstag", "txt_Geburtsort", "txt_Anz_Kinder", _
              "txt_Strasse", "cbo_Plz_IDref", "cbo_Stadtsangehoerichkeit_Land_IDRef")


    L = Array("cbo_AnredeID", "txt_Nachname", "txt_Vorname", "cbo_Geschlecht", _
              "txt_Geburtsname", "cbo_Familienstand", "txt_Geburtstag", "txt_Anz_Kinder", _
              "txt_Strasse", "cbo_Plz_IDref", "cbo_Stadtsangehoerichkeit_Land_IDRef")

    If UBound(L) >= 0 Then
        For i = 0 To UBound(L)
            ctrlName = "Me!" & L(i)
            If Nz(ctrlName, "") = "" Then Prüfen = False
            Debug.Print Prüfen
        Next i
    End If

    If Prüfen = True Then
        ToggleControlProperty Forms!frm_Mitarbeiter_Anlegen, A
    End If
End Sub


Sind alle Felder gefüllt  soll die Funktion alle Felder in Formular ändern außer die in A = Array
L = Array sind die Felder die Pflicht eingaben sind 
Hier würde ich gerne wissen ob If IsArray anders in die Funktion einbauen werden kann und die Sprung Marke "GoTo weiter" anders gestaltet werden kann

        If IsArray(ctrName) Then
            For i = 0 To UBound(ctrName)
                If ctrName(i) = ctrl.Name Then
                    GoTo weiter
                End If
            Next i
        End If


Public Function ToggleControlProperty(ByRef Frm As Form, Optional ctrName As Variant)
    Dim ctrl As Control
    Dim A As Integer
    Dim i As Integer
    Dim Status As String
    For Each ctrl In Frm.Section(acDetail).Controls

        If IsArray(ctrName) Then
            For i = 0 To UBound(ctrName)
                If ctrName(i) = ctrl.Name Then
                    GoTo weiter
                End If
            Next i
        End If

        With ctrl
            Select Case .ControlType
            Case acTextBox
                If .Enabled = True Then
                    .Enabled = False
                    'Status = "deaktiviert"
                Else
                    .Enabled = True
                    'Status = "aktiviert"
                End If
            Case acListBox
                If .Enabled = True Then
                    .Enabled = False
                    'Status = "deaktiviert"
                Else
                    .Enabled = True
                    'Status = "aktiviert"
                End If
            Case acOptionButton
                If .Enabled = True Then
                    .Enabled = False
                    'Status = "deaktiviert"
                Else
                    .Enabled = True
                    'Status = "aktiviert"
                End If
            Case acComboBox
                If .Enabled = True Then
                    .Enabled = False
                    'Status = "deaktiviert"
                Else
                    .Enabled = True
                    'Status = "aktiviert"
                End If
            Case acSubform
                If .Enabled = True Then
                    .Enabled = False
                    'Status = "deaktiviert"
                Else
                    .Enabled = True
                    'Status = "aktiviert"
                End If
            Case acCommandButton
                If .Enabled = True Then
                    .Enabled = False
                    'Status = "deaktiviert"
                Else
                    .Enabled = True
                    'Status = "aktiviert"
                End If
            Case acOptionGroup
                If .Enabled = True Then
                    .Enabled = False
                    'Status = "deaktiviert"
                Else
                    .Enabled = True
                    'Status = "aktiviert"
                End If
            End Select
        End With

weiter:
    Next ctrl

End Function


Ich würde mich riesig freuen wenn einer Lust hat mir zu helfen

Gruß Frank
Titel: Re: Felder auf inhalt prüfen mit Array
Beitrag von: DF6GL am November 16, 2014, 16:54:25
Hallo,


vermutlich sollte das so lauten:

For i = 0 To UBound(L)
              If Nz(Me(L(i),"")= "" Then Prüfen = False
        Next i

Titel: Re: Felder auf inhalt prüfen mit Array
Beitrag von: Frank77 am November 16, 2014, 18:25:47
Hallo!

Danke für die hilfe es funktioniert

Private Sub cmd_Speichern_Click()
    Dim ctl As Control
    Dim A As Variant
    Dim L As Variant
    Dim i As Integer
    Dim ctrlName As String
    Dim Prüfen As Boolean
    Prüfen = True

    A = Array("Rahmen_Personendaten", "cmd_Speichern", "cbo_AnredeID", "txt_Nachname", "txt_Vorname", "cbo_Geschlecht", _
              "txt_Geburtsname", "cbo_Familienstand", "txt_Geburtstag", "txt_Geburtsort", "txt_Anz_Kinder", _
              "txt_Strasse", "cbo_Plz_IDref", "cbo_Stadtsangehoerichkeit_Land_IDRef")


    L = Array("cbo_AnredeID", "txt_Nachname", "txt_Vorname", "cbo_Geschlecht", _
              "cbo_Familienstand", "txt_Geburtstag", "txt_Anz_Kinder", _
              "txt_Strasse", "cbo_Plz_IDref", "cbo_Stadtsangehoerichkeit_Land_IDRef")

    If UBound(L) >= 0 Then
        For i = 0 To UBound(L)
            If Nz(Me(L(i)), "") = "" Then Prüfen = False
        Next i
    End If

    If Prüfen = False Then MsgBox "bitte erst alle Felder mit * ausfüllen.", vbInformation Or vbOKOnly, "fehler:"
    If Prüfen = True Then
        DoCmd.RunCommand acCmdSaveRecord
        ToggleControlProperty Forms!frm_Mitarbeiter_Anlegen, A
        Me!cmd_Speichern.Enabled = False
    End If
End Sub