Only save record when all fields required are complete

charlie442

Registered User.
Local time
Today, 17:51
Joined
Jan 14, 2011
Messages
53
Hi gurus

I have a data entry form which has certain fields for which I require the information. I have set Validation Rules and Messages up for those fields in the underlying tables but not set them to required. These work as I tab through the form.
However when I create a button on the form with

DoCmd.RunCommand acCmdSaveRecord

I am now getting ugly error messages which give the user an option to debug which I definitely do not need. I am new to VBA. What is the best way around this issue

Thanks
Charles
 
What about taking this approach

Check Fields Validation

Create a form and select design view. Select the Fields you need to be completed. Open the properties and select Tag (Check the other Tab). Add a word in this case “Vital”.

Private Sub cmdButton_Click()
Dim ctl as Control
Dim Flag as Boolean

For Each ctl in Form_Name
If ctl.tag=”vital” Then
If isNull(ctl.Value) Then
Ctl.BackColor=vbRed
Flag=True
Else
Ctl.BackColor=vbWhite
End If
End IF
Next
If Flag = True Then
MsgBox”Please Enter data in the fields indicated with a red background"
Else
DoCmd.RunCommand acCmdSaveRecord
End If
 
If any field is "dirtied", i.e. the user typed something, then any attempt to leave the record will result in Access trying to save it. You therefore also need to do your checks in the BeforeUpdate event and cancel the update, if data is missing. Search for BeforeUpdate on the forum.
 
Pleased to read you have a working solution.

Just a note for the future.

When you design a table if you want to set something so you want people to fill things in, but they may not have the information to hand but need to save and move on to the next record you can add a format so it displays some defualt text in a colour and once the user fills it in it then removes the default text and colour and retains the text that has been added.

So to see this, look at creating a temp table with a field in it as text and in the properties in the Format add something like this in.

@;"Fill me in"[Red]
 

Users who are viewing this thread

Back
Top Bottom