access16, set field mandatory & display error by not saving record

akika

Registered User.
Local time
Today, 14:47
Joined
Aug 7, 2018
Messages
102
hi,

i got a forms with several fields in it. (optional & mandatory)

mandatory fields
cust.Name
CustID
Type
Debt

I have a save button done via on click embedded macro.

In the database field, ive set Required to Yes for these fields.
How can i amend same that when thse fields are blanks.. an error is thrown and record is not saved.
 
Hi. Are you saying clicking on the Save button does not produce any error and saves the record even if you leave the required fields blank?
 
akika,

Please provide more info on your set up and what you are experiencing.
Do you really have a field named cust.Name?
I'm pretty sure Type is a reserved word for Access???
 
Actually,

if i leave field CustID which is mandatory blanks and goes to next optional text field description
and click on Save butn
I get msg ' Record has been saved' with Ok btn
when click on ok
I get error [MacroError].[Description] with ok btn

is there a way to change the display msg..
or how to throw an error once the field is left blank


ive try below also.. BUt what the best way to do that ??


Private Sub CIR_LostFocus()

If IsNull(CIR) Then
MsgBox "Please enter the required date", vbOKOnly
Cancel = True
Me.CIR.SetFocus
End If

End Sub
 
Hi. Before we go any further. What does the code you have behind the "Save" button look like?
 
save btn contains the attached embedded macro.
 

Attachments

  • saveCapture.PNG
    saveCapture.PNG
    8.9 KB · Views: 91
Okay, thanks. This tells me you are getting the "record saved" message box but also gets the "cannot save record" error message, which is confusing, correct? You can move the first MessageBox command inside the If [MacroError]<>0 Then by adding a Else branch to it. If you want to have a more meaningful error message though, I can only give you VBA suggestions because I'm not very good with macros.
 
yeah indeed its confusing wz that embedded macros.

Can we implement same via vba? and how to do it??
 
Hi. But first, try it out by moving the first message box below the second one, just to avoid some confusion. So, it should somewhat look like this:


Code:
RunCommand
    Command SaveRecord
If [MacroError]<>0 Then
    MessageBox
       Message "Error"
Else
    MessageBox
       Message "Saved"
End If
Let us know how you like it, then we can go another way if it's not what you want.
 
yes it seems ok with below code.
:)
thxs a lot
 

Users who are viewing this thread

Back
Top Bottom