Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restricting the user

Status
Not open for further replies.

pcdaveh

Technical User
Sep 26, 2000
213
US
I have a form that allows the user to manipulate the records in a table. But the totals of those records must remain in balance to a total that is calculated each time they pull up a new customer. If the form isn't in balance I don't want the user to be able to exit that form or choose a new customer, Close the application or go to another form. Help?
 
Hi PCDaveH

Have you tried writing an onClose event. Something like:

Private Sub Form_Close()
if Me.txtSomething<>MyBalance then
msgbox &quot;Can't close form because...&quot;,vbCritical,&quot;someTitle&quot;
endif
End Sub

Hope this helps,
Rewdee
 
The suggested OnClose event will work fine for exiting the form, but not if the user goes to another records.

My approach would be to devise a test to detect the imbalance and then turn on a warning on the form advising the user not to close the form or go to another record until the imbalance is corrected. If you have room on the form you can place a warning and set its visible property to false unless an imbalance is detected. Put the test in the OnCurrent event and something like the other suggestion to prevent closing of the form.

Hope this helps,

Uncle Jack
 
Hi!

Form level validation should be performed in the BeforeUpdate event procedure of the form. If the information that the user input fails the test then set Cancel = -1 and the form will automatically cancel the changes and force the user to remain in the form until the validation succeeds. Now, if you will give more information on the validation you want to do then we can help you achieve your goal and avoid some pitfalls. One pitfall that comes to mind is, if the user will need to change more than one record to maintain the balance, then the validation in the BeforeUpdate will always fail. Give us more information and we will do our best to help.

hth
Jeff Bridgham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top