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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 ifs

Status
Not open for further replies.

scottian

Programmer
Jul 3, 2003
955
GB
im building a database to store a departments daily figures and on the close of a form i need to check things. one that there are no negative values in the outstanding figures fields and two that the date of the figures is not in the future. what i need to happen is that if on close event if any figure is negative a pop up window will appear to inform that "negative values are not allowed" and then the close is stopped or if the date is in the future then a different pop up window appears to inform that the date is in the future and again stop the form from closing
 
i would suggest deactivating the close button at the top of the window, and creating your own close button.then you can have all this processing, and if all is well do me.close at the end

the problem with the close function at the top right is that once clicked, the form is already closed, so any processing won't be able to stop this. as far as i'm aware.

hope this helps
 
NEGATIVE VALUES IF STATEMENT

IF me.txtValue.value < 0 THEN
msgbox &quot;negative values are not allowed&quot;
END IF


CHECK DATE
(Not sure on this if somone can correct it if reqd.)

Dim myDate as Date

myDate = me.txtDate.Value

IF myDate > date THEN
msgbox &quot;Date in Future&quot;
END IF

Is this wat you are looking for???
 
Hmmm

Stopping the form from closing, is a bit funny. You see, disabling closebuttons etc, does not prevent the user from using CTRL+W/CTRL+F4 to close a form.

Declare a form level variable on the top of your form module

Private mfCloseOK as Boolean

In the Forms OnLoad event set it to false

When the user presses the close button (you'll have to create a close button), then set the mfCloseOK variable to true, only when all criterias are met.

Then, in the only event where you can cancel closing of the form - use the following line:

Cancel = Not mfCloseOK

This will prevent the user from closing the form unntil all criterias are met.

HTH Roy-Vidar

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top