Checking Data (1 Viewer)

Kundan

Registered User.
Local time
Today, 05:09
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

  • Database1.zip
    81.7 KB · Views: 52

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 12:09
Joined
Jul 9, 2003
Messages
16,244
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.
 

Kundan

Registered User.
Local time
Today, 05:09
Joined
Mar 23, 2019
Messages
118
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
 

bob fitz

AWF VIP
Local time
Today, 12:09
Joined
May 23, 2011
Messages
4,717
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
 

Kundan

Registered User.
Local time
Today, 05:09
Joined
Mar 23, 2019
Messages
118
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?
 

bob fitz

AWF VIP
Local time
Today, 12:09
Joined
May 23, 2011
Messages
4,717
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.
 

Kundan

Registered User.
Local time
Today, 05:09
Joined
Mar 23, 2019
Messages
118
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

  • Database1.zip
    87.6 KB · Views: 47

bob fitz

AWF VIP
Local time
Today, 12:09
Joined
May 23, 2011
Messages
4,717
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

  • ValCheck02.zip
    86.9 KB · Views: 40

Kundan

Registered User.
Local time
Today, 05:09
Joined
Mar 23, 2019
Messages
118
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?
 

Dreamweaver

Well-known member
Local time
Today, 12:09
Joined
Nov 28, 2005
Messages
2,466
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)
 

bob fitz

AWF VIP
Local time
Today, 12:09
Joined
May 23, 2011
Messages
4,717
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.
 

Kundan

Registered User.
Local time
Today, 05:09
Joined
Mar 23, 2019
Messages
118
I put it in the Before Update of the control , but it is not working.
 

Attachments

  • ValCheck02.zip
    86.9 KB · Views: 45

bob fitz

AWF VIP
Local time
Today, 12:09
Joined
May 23, 2011
Messages
4,717
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.
 

bob fitz

AWF VIP
Local time
Today, 12:09
Joined
May 23, 2011
Messages
4,717
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
 

missinglinq

AWF VIP
Local time
Today, 08:09
Joined
Jun 20, 2003
Messages
6,423
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)>
 

bob fitz

AWF VIP
Local time
Today, 12:09
Joined
May 23, 2011
Messages
4,717
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
 

Kundan

Registered User.
Local time
Today, 05:09
Joined
Mar 23, 2019
Messages
118
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?
 

Kundan

Registered User.
Local time
Today, 05:09
Joined
Mar 23, 2019
Messages
118
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.
 

missinglinq

AWF VIP
Local time
Today, 08:09
Joined
Jun 20, 2003
Messages
6,423
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

Top Bottom