Help to code

A

an

Hello!

I have a form to add mew records in a table.
I would like a code in Before Update, through message box,
for:

1 - If the user click to close the form with any field
without data, the MsgBox alert to the empty field name;
2 - The user will be able to continue or to leave;
3 - If to continue, the cursor to get off field;
4 - If all fields they will be filled, save and close.

I have the next code but don't work fine.

Dim strField As String
Dim vFields As Variant
Dim i As Integer
Dim strMsg As String

vFields = Split("Field1,Field2,Field3")

For i = 0 To UBound(vFields, 1)
If IsNull(Me(vFields(i))) = True Then
strField = vFields(i)
Exit For
End If
Next i

If strField <> "" Then

If strMsg = strField + "Empty data" & vbCrLf & "Do you
insert data?" Then

If MsgBox(strField, vbYesNo + vbExclamation, "To
whrite data") = vbYes Then
Me(strField).SetFocus
Cancel = True
DoCmd.RunCommand acCmdUndo
Else
Me.Undo
End If
End If
End If

I would like your help for this.
Thanks in advance.
an
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top