formsms-accesscomboboxrequired-field

MsAccess form - empty records originally, but needed to be filled mandatory, once the data entry started


I have MsAccess Form:

ClientName, ID fields - records filled with the information
Gender, Race, PrimaryLanguage fields (combo box type) are empty records

Users will fill Gender, Race and PrimaryLanguage, PrimaryDisability fields with the information. My goal is - before user will move to the next record, I want he to be unable to proceed until those fields (Gender / Race) are filled with its content.

The problem is - Gender / Race / PrimaryLanguage, PrimaryDisability for the existing clients have to stay empty, but at the same time - when user starts filling it, it needs to be filled mandatory.

It works this way only in case if I am adding a new record. (I have Gender / Race fields as required) - but doesn't work with the existing records.

PS - the answer provided below is great, but worked on my end for 2 fields only What about 3 or more fields?

I had idea of adding the event procedure to each button in the Form, not to the whole Form. code should be something like:

Private Sub Gender_BeforeUpdate(Cancel As Integer)
    If Nz(Me.Gender, "") = "" And (Nz(Me.Race, "") <> "" 
       Or (Nz(Me. PrimaryLanguage, "") <> ""  
       Or (Nz(Me. PrimaryDisability, "") <> "")
    Then
       MsgBox "Select Gender", vbInformation
       Cancel = True
   End If
End Sub

But it says about syntax mistakes

Please help!


Solution

  • Use BeforeUpdate event to cancel updating of a record before moving to another record

     Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    
      If Nz(Me.ClientName, "") <> "" And Nz(Me.Gender, "") = "" And Nz(Me.Race, "") = "" And Nz(Me.PrimaryLanguage, "") = "" And Nz(Me.PrimaryDisability, "") = "" Then
              Exit Sub
      End If
    
      If Nz(Me.Gender, "") = "" Then
              MsgBox "Select Gender", vbInformation
              Cancel = True
              Exit Sub
         End If
    
        If Nz(Me.Race, "") = "" Then
              MsgBox "Select Race", vbInformation
              Cancel = True
              Exit Sub
         End If
    
         If Nz(Me.PrimaryLanguage, "") = "" Then
              MsgBox "Enter PrimaryLanguage", vbInformation
              Cancel = True
              Exit Sub
         End If
    
         If Nz(Me.PrimaryDisability, "") = "" Then
              MsgBox "Enter PrimaryDisability ", vbInformation
              Cancel = True
              Exit Sub
         End If
    End Sub