Checking Data

Kundan

Registered User.
Local time
Today, 10:34
Joined
Mar 23, 2019
Messages
118
In the attached DB if someone misses to enter AMOUNTs I have written a code to check that but it is not working.
 

Attachments

It would be useful if you would post the code snippet in The thread as many of us use mobile phones which are not able to run MS Access.
 
It would be useful if you would post the code snippet in The thread as many of us use mobile phones which are not able to run MS Access.

Code:
If (IsNull(Me.AMOUNTs) Or (Me.AMOUNTs = 0)) Then
If MsgBox("Did you miss AMOUNT?", vbDefaultButton1 + vbYesNo + vbQuestion) = vbYes Then
Me.AMOUNTs.SetFocus
End If
End If
 
Use the following code in the forms BeForeUpDate event:
Code:
If (IsNull(Me.AMOUNTs) Or (Me.AMOUNTs = 0)) Then
    If MsgBox("Did you miss AMOUNT?", vbDefaultButton1 + vbYesNo + vbQuestion) = vbYes Then
        Me.AMOUNTs.SetFocus
        Cancel = True
    End If
End If
 
Use the following code in the forms BeForeUpDate event:
Code:
If (IsNull(Me.AMOUNTs) Or (Me.AMOUNTs = 0)) Then
    If MsgBox("Did you miss AMOUNT?", vbDefaultButton1 + vbYesNo + vbQuestion) = vbYes Then
        Me.AMOUNTs.SetFocus
        Cancel = True
    End If
End If

The field is currency. By default it shows Rs. 0.00. If someone crosses over without entering, how do I check? Will -> If (Me.AMOUNTs = Rs. 0.00) work?
 
The field is currency. By default it shows Rs. 0.00. If someone crosses over without entering, how do I check? Will -> If (Me.AMOUNTs = Rs. 0.00) work?
I don't think that it will work on an existing record if user deletes the amount. Best to test for Null as well as 0, just in case.
 
I don't think that it will work on an existing record if user deletes the amount. Best to test for Null as well as 0, just in case.
The field is currency. By default it shows Rs. 0.00. If someone crosses over without entering, how do I check? Will -> If (Me.AMOUNTs = Rs. 0.00) work?
I don't think that it will work on an existing record if user deletes the amount. Best to test for Null as well as 0, just in case.
I am attaching the changes. But it is not working properly.
 

Attachments

I suspect that it "is not working properly" because you have not put the code in the FORMs BeforeUpdate event as I suggested in my earlier post.

Try the attached db:
 

Attachments

I suspect that it "is not working properly" because you have not put the code in the FORMs BeforeUpdate event as I suggested in my earlier post.

Try the attached db:

Yes it works in the forms' Before Update event. Why is it not possible in the AMOUNTs Before Update event?
 
I have been looking for a post but couldn't find it so posting a link to my site
You could use this function or just the IsNothing function you would only need to to do something like
Cancel = Isnothing(Me.AMOUNTs)
Global Validation (Require Entry)
 
Yes it works in the forms' Before Update event. Why is it not possible in the AMOUNTs Before Update event?
It does work in the controls Before Update event but you need to remove the "setfocus" line as that is not needed and will throw an error. I think you had the code in the controls AfterUpdate event.
 
I put it in the Before Update of the control , but it is not working.
 

Attachments

I put it in the Before Update of the control , but it is not working.
So why not use the FORMs Before Update event. I am not at a computer today but will look at your db tomorrow.
 
I put it in the Before Update of the control , but it is not working.
First of all, please accept my sincere apologies for not replying sooner as I had promised.

I'm not sure what you mean exactly by "it is not working", so I am guessing that after selecting "Yes" in the message box the focus returns to the "AMOUNTs" control but the original figure is not reinstated unless you press the "Esc" key on the keybpard.

This effect can be achieved within the code by adding the line:

Me.Undo

as follows:

Code:
Private Sub AMOUNTs_BeforeUpdate(Cancel As Integer)
    If (IsNull(Me.AMOUNTs) Or (Me.AMOUNTs = 0)) Then
        If MsgBox("Did you miss AMOUNT?", vbDefaultButton1 + vbYesNo + vbQuestion) = vbYes Then
            Cancel = True
            Me.Undo
        End If
    End If
End Sub
 
Why is it not possible in the AMOUNTs Before Update event?
Placing it in the Control's BeforeUpdate event is useless!

All the user has to do, in order to make your validation useless...is to simply not enter the Amounts Control! If the Control is never entered...none of its events are executed!

Validation for determining if a Control is populated simply has to be in the Form_BeforeUpdate event...as does validation involving two or more Controls...such as ControlB must be greater than ControlA, etc.

Validation used in a Control's BeforeUpdate is used to ensure that data that has actually been entered meets a requirement...such as 'greater than current date,' or 'must include at least one Alpha character,' etc.

Linq ;0)>
 
Placing it in the Control's BeforeUpdate event is useless!

All the user has to do, in order to make your validation useless...is to simply not enter the Amounts Control! If the Control is never entered...none of its events are executed!

Validation for determining if a Control is populated simply has to be in the Form_BeforeUpdate event...as does validation involving two or more Controls...such as ControlB must be greater than ControlA, etc.

Validation used in a Control's BeforeUpdate is used to ensure that data that has actually been entered meets a requirement...such as 'greater than current date,' or 'must include at least one Alpha character,' etc.

Linq ;0)>
I agree entirely with you missingling, which is why I advised the use of the form's BeforeUpdate event in post #5 and #8
 
Placing it in the Control's BeforeUpdate event is useless!

All the user has to do, in order to make your validation useless...is to simply not enter the Amounts Control! If the Control is never entered...none of its events are executed!

Validation for determining if a Control is populated simply has to be in the Form_BeforeUpdate event...as does validation involving two or more Controls...such as ControlB must be greater than ControlA, etc.

Validation used in a Control's BeforeUpdate is used to ensure that data that has actually been entered meets a requirement...such as 'greater than current date,' or 'must include at least one Alpha character,' etc.

Linq ;0)>
How would the code be in the BeforeUpdate event of the control?
 
I agree entirely with you missingling, which is why I advised the use of the form's BeforeUpdate event in post #5 and #8

I found the following:
If (IsNull(Me.AMOUNTs) Or (Me.AMOUNTs = 0)) Then
If MsgBox("Did you miss AMOUNT?", vbDefaultButton1 + vbYesNo + vbQuestion) = vbYes Then
Cancel = True
'Me.AMOUNTs.SetFocus
End If
End If

working better on the OnExit event of the control.
 
Q. And what happens if the user never enters the Control at all?

A. NOTHING! The validation code never fires!

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom