• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 60
  • Last Modified:

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
0
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Asked:
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
  • 4
  • 3
  • 2
  • +1
1 Solution
 
Ryan ChongCommented:
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 ChongCommented:
Under form after update
i was mentioned in the AfterUpdate event of txtbalance not form's AfterUpdate event.

can you try that?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
 
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAuthor Commented:
Thank you
0
 
Gustav BrockCIOCommented:
You are welcome!

/gustav
0
 
Dale FyeCommented:
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 ChongCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now