Validating controls

Validating controls

I have a control on the [parent form purchases] which sums the total value of goods received note from the tables (txtgrnValue). This control is used to net off with the purchases subform (txtgrandtotal), for simplicit purpose see below:

Txtgrnvalue – txtgrandtotal = 0 (txtbalance)

If the net of the above two controls is zero (txtbalance), then it is safe for the users to proceed to the next sub form which deals with double entries.

Now assuming the net of the two is not zero (txtbalance), I want to stop the users from proceeding to next sub form until the above control is balanced off to zero.
How do I do it????
Which event to use???????


Regards
Chris
LVL 3
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
in the AfterUpdate event of txtbalance, try to check if its value is greater than zero, if yes, disable your "Next" button or so, else enable that option.
0
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAuthor Commented:
Kindly demonstrate your answer properly, are saying it is supposed to

Under form after update like below:

If (Me.txtbalance) <> 0 Then
Beep
MsgBox " Please check the txtbalance control is out of balance"
Cancel = True
Exit Sub
End If
End Sub

I have tried it , it is not working!!!!!!!!

Regards

Chris
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
Under form after update
i was mentioned in the AfterUpdate event of txtbalance not form's AfterUpdate event.

can you try that?
0
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAuthor Commented:
A constant message keeps on popping up

What I want is a situation like after updating the sub form and immediately when attempting to leave the sub form to the next sub form then that message should pop up if the txtbalance control is not zero. Is there a way to do it in ms access!

Regards

Chris
0
Gustav BrockCIOCommented:
You can do like this:

Option Compare Database
Option Explicit
    
' Form module declarations.
Private LastMark    As String
Private LastValue   As Currency

Private Sub Form_AfterUpdate()

    ' Store the last updated value.
    LastValue = Nz(Me!Txtgrnvalue.Value, 0)

End Sub

Private Sub Form_Current()
    
    If LastValue <> 0 And LastMark <> "" Then
        ' The last sum was not zero, and we do have a valid bookmark.
        ' Move to the last record.
        Me.Bookmark = LastMark
        ' Pop a message to the user.
        MsgBox "Please adjust to zero."
        Me!Txtgrnvalue.SetFocus
    Else
        ' Store the current value to allow us to check if it was not zero.
        LastValue = Nz(Me!Txtgrnvalue.Value, 0)
        ' Store the current bookmark to allow us to get back to this.
        LastMark = Me.Bookmark
    End If
    
End Sub

Open in new window

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAuthor Commented:
Thank you
0
Gustav BrockCIOCommented:
You are welcome!

/gustav
0
Dale FyeOwner, Developing Solutions LLCCommented:
The other thing I do with subforms with this type of functionality is use the subform controls Exit event, which has a Cancel argument.

You would open your main form in design view, click on the subform control and view the properties of the control.  Select the Exit property and then do something like:

Private Sub subForm1_Exit (Cancel as integer)

    Cancel = me.subform1.form.textbox <> 0
    if Cancel then
        msgbox "balance the values before proceeding"
        me.subform1.form.textbox.setfocus
    end if

End Sub

Open in new window

0
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAuthor Commented:
Thank you so much this is actually the best answer , but how I reopen this query to apportion the points to you as well???????????

Once again

Thank you so much

Chris
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
but how I reopen this query to apportion the points to you as well???????????
you can try click the "Report Question" option.

How do I report content to site advisers and moderators?
http://support.experts-exchange.com/customer/portal/articles/2876519-how-do-i-report-content-to-site-advisers-and-moderators-
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.