jeudi 30 août 2018

Close Form if Field is Blank

I have a form that if a field is blank, it tells the user that it can't be blank, and gives the user the option to fill in the blank field (Yes) or close the form (No). Problem is that when the user picks No (or close the form), it gives me a run-time error 2585. After researching, I have it checking if the field is blank on the field after using On Got Focus. (After Update on the field didn't work because there's no update if it's blank.) Here's my code:

If IsNull(Me.txtSSN) Then

  strMsg = "Social Security Number Must Not Be Left Blank!" & vbCrLf
  strMsg = strMsg & "Do you want to add new veteran's record?" & vbCrLf

  If MsgBox(strMsg, vbQuestion + vbYesNo, "Go to Record?") = vbYes Then

    Me.Undo
    Me.Refresh
    Me.txtSSN.SetFocus
    Exit Sub

  Else
    Me.Undo
    Me.Refresh
    Me.txtSSN.SetFocus

    Me.Undo
    'DoCmd.OpenForm "fmuMainMenu"
    DoCmd.Close acForm, "frmVetNewMainForm"

  End If

Else 'Rest of Code...

Aucun commentaire:

Enregistrer un commentaire