0
votes

I have a database for dairy farm records. It has a form where I have details of cows and picture of them. One the form I have field [GENDER]. I want that when i select [MALE] from this field [Gender]. It should disable other fields on the form. and when i select [FEMALE]. It should enable other fields on the form. Form should open with fields disable if selection is [MALE] and enabled if selection is [FEMALE].

Private Sub Gender AfterUpdate ()

If Gender.Value = "Male" Then

CalvingStatus.Enabled = False

MilkDay.Enabled = False

Else if Gender.Value = "Female" Then

CalvingStatus.Enabled = True

MilkDay.Enabled = True

Else

CalvingStatus.Enabled = False

MilkDay.Enabled = False

End if

End Sub
1
Seems like you missed the tour and read How to Ask! That will show you how to format and highlight code, then update question! - ComputerVersteher
Actual code only changes after you updated Gender as it resides in the event raised on that. If same should happen after opened form, maybe there is an event raised on that action (read the docs on form- events) ;) - ComputerVersteher

1 Answers

0
votes
Private Sub Form_Current()
    EnableDisable
End Sub

Private Sub Gender_AfterUpdate()
    EnableDisable
End Sub

Private Sub EnableDisable()
    If Gender.Value = "Male" Then
        CalvingStatus.Enabled = False
        MilkDay.Enabled = False
    ElseIf Gender.Value = "Female" Then
        CalvingStatus.Enabled = True
        MilkDay.Enabled = True
    Else
        CalvingStatus.Enabled = False
        MilkDay.Enabled = False
    End If
End Sub