Combi: Empty field check + Next record

Teuntja123

Registered User.
Local time
Yesterday, 22:58
Joined
Sep 17, 2013
Messages
21
Hi all,

I created a form where people to fill in some data.
After they are done with this, they should hit the 'next' button and the record will be stored * they will start over with a new/empty form.

Because they sometimes forgot to fill in some data I created a check on the 'next button', so my SQL like as follow right now:

Private Sub Button_Save_New_Click()

If IsNull("FIELD1") Or IsNull("FIELD2")...Then
MsgBox "Missing info!", , "Incomplete Form!"
End If

On Error GoTo Err_addnew_Click
DoCmd.GoToRecord , , acNewRec
Exit_addnew_Click:
Exit Sub
Err_addnew_Click:
MsgBox Err.Description
Resume Exit_addnew_Click
End Sub


The problem is that when they forgot something, the pop-up will come, but after hitting Ok, it will still save & go to the next error.

Can someone help me with adjusting the code so it will only go the next if there will be no empty fields?

Kind Regards, Teun
 
Well what you try to do is if field1 or field2 is empty, display a message then check if there was some kind of error. Since there are no errors, your code will just go to the gotorecord and start a new record.

To fix that, you just need a Exit Sub right after the message box is displayed.
 
Code:
Private Sub Button_Save_New_Click()

if IsValidForm() then DoCmd.GoToRecord , , acNewRec
end sub


Private Function IsValidForm() As Boolean
Dim vMsg
Select Case True
   Case IsNull(txtFile)
      vMsg = "File is missing"
   Case IsNull(txtTblData)
      vMsg = "Table name is missing"
   Case IsNull(cboState)
      vMsg = "State is missing"
End Select
If vMsg <> "" Then MsgBox vMsg, vbCritical, "Required Field"
IsValidForm = vMsg = ""
End Function
 
Personally I'm not very fond of the check all the field one by one.
What can happen is that if the user don't fill 2 field he will get 2 messages. First one will tell him to fill the first field. And second one will tell him to fill the second field.

giving the user 1 message box with all the fields that are missing is far more productive.
(And if possible change the border color of the missing fields to red.)
 

Users who are viewing this thread

Back
Top Bottom