Force Users to Update the Required Fields Before Saving Record

G

Guest

I have a form with the following fields: Job Number, Job Description,
Assigned to, Tasks, Cost and Completion Date. I want to required user who
make change to the Tasks field, also update the Cost and Completion Date
fields, otherwise they get a warning/error message and can't save the record.
Is there any way to do it?

Thanks,
Mike
 
A

Allen Browne

If you want to prevent the user from saving a record if these fields are
blank, open your table in design view, and in the lower pane set the
Required property to Yes for each field.

If you want to give a warning message but allow them to save anyway, use the
BeforeUpdate event procedure of the form:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If IsNull(Me.[Job Description] Then
strMsg = strMsg & "Blank job description" & vbcrlf
End If

If IsNull(Me.[Assigned to] Then
strMsg = strMsg & "Assigned to is blank." & vbcrlf
End If

'and so on

If Len(strMsg) > 0 Then
strMsg = strMsg & vbCrLf & "Continue anyway?"
If MsgBox strMsg, vbYesNo + vbDefaultButton2 <> vbYes Then
Cancel = True
'Me.Undo
End If
End If
End Sub
 

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