dbTalk Databases Forums  

Prevent form closing if criteria not met

comp.databases.ms-access comp.databases.ms-access


Discuss Prevent form closing if criteria not met in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
A_Classic_Man
 
Posts: n/a

Default Prevent form closing if criteria not met - 02-14-2011 , 09:56 AM






I have a form, EmpForm with a subform, Activity. There are two
controls on the mainform. First control entitled HoursWorked
calculates data from two fields on the mainform,=DateDiff("s",
[StartTime],[EndTime])/3600. The second control, ActivityHours
calcualates data from the subform, =frmActivity.Form!TotalHrs.

I need the code to put behind the Close button on the Mainform which
will prevent the mainform and subform form closing unless the
HoursWorked and ActivityHours are equal.

Thank you for your help

Ron

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: Prevent form closing if criteria not met - 02-14-2011 , 11:11 AM






A_Classic_Man wrote:

Quote:
I have a form, EmpForm with a subform, Activity. There are two
controls on the mainform. First control entitled HoursWorked
calculates data from two fields on the mainform,=DateDiff("s",
[StartTime],[EndTime])/3600. The second control, ActivityHours
calcualates data from the subform, =frmActivity.Form!TotalHrs.

I need the code to put behind the Close button on the Mainform which
will prevent the mainform and subform form closing unless the
HoursWorked and ActivityHours are equal.

Thank you for your help

Ron
Perhaps something similar to the following might work.
If Me.YourMainFormControlName <>_
Me.YourSubformName!YourSubformsControlName then
Msgbox "Values don't match!"
else
Docmd.Close acForm, Me.name
Endif

Reply With Quote
  #3  
Old   
A_Classic_Man
 
Posts: n/a

Default Re: Prevent form closing if criteria not met - 02-14-2011 , 03:43 PM



On Feb 14, 11:11*am, Salad <sa... (AT) oilandvinegar (DOT) com> wrote:
Quote:
A_Classic_Man wrote:
I have a form, EmpForm with a subform, Activity. There are two
controls on the mainform. First control entitled HoursWorked
calculates data from two fields on the mainform,=DateDiff("s",
[StartTime],[EndTime])/3600. The second control, ActivityHours
calcualates data from the subform, =frmActivity.Form!TotalHrs.

I need the code to put behind the Close button on the Mainform which
will prevent the mainform and subform form closing unless the
HoursWorked and ActivityHours are equal.

Thank you for your help

Ron

Perhaps something similar to the following might work.
If Me.YourMainFormControlName <>_
* * * * Me.YourSubformName!YourSubformsControlName then
* *Msgbox "Values don't match!"
else
* *Docmd.Close acForm, Me.name
Endif
Thank you, your help is appreciated.

Reply With Quote
  #4  
Old   
Salad
 
Posts: n/a

Default Re: Prevent form closing if criteria not met - 02-14-2011 , 04:36 PM



A_Classic_Man wrote:

Quote:
On Feb 14, 11:11 am, Salad <sa... (AT) oilandvinegar (DOT) com> wrote:

A_Classic_Man wrote:

I have a form, EmpForm with a subform, Activity. There are two
controls on the mainform. First control entitled HoursWorked
calculates data from two fields on the mainform,=DateDiff("s",
[StartTime],[EndTime])/3600. The second control, ActivityHours
calcualates data from the subform, =frmActivity.Form!TotalHrs.

I need the code to put behind the Close button on the Mainform which
will prevent the mainform and subform form closing unless the
HoursWorked and ActivityHours are equal.

Thank you for your help

Ron

Perhaps something similar to the following might work.
If Me.YourMainFormControlName <>_
Me.YourSubformName!YourSubformsControlName then
Msgbox "Values don't match!"
else
Docmd.Close acForm, Me.name
Endif


Thank you, your help is appreciated.
Do realize that if there are no records in you subform it will probably
error.
If Me.YourSubformName.Form.Recordcount > 0 then...
'do your check
endif

Also, if you have an X button, it will run your code and close as well.
If a record exists, you can cancel the Unload. If it's a new record I
don't think there's a built in way to determine the X was trapped, so
you'd get the error message and then it would close.

Reply With Quote
  #5  
Old   
Phil
 
Posts: n/a

Default Re: Prevent form closing if criteria not met - 02-15-2011 , 02:28 AM



On 14/02/2011 22:36:37, Salad wrote:
Quote:
A_Classic_Man wrote:

On Feb 14, 11:11 am, Salad <sa... (AT) oilandvinegar (DOT) com> wrote:

A_Classic_Man wrote:

I have a form, EmpForm with a subform, Activity. There are two
controls on the mainform. First control entitled HoursWorked
calculates data from two fields on the mainform,=DateDiff("s",
[StartTime],[EndTime])/3600. The second control, ActivityHours
calcualates data from the subform, =frmActivity.Form!TotalHrs.

I need the code to put behind the Close button on the Mainform which
will prevent the mainform and subform form closing unless the
HoursWorked and ActivityHours are equal.

Thank you for your help

Ron

Perhaps something similar to the following might work.
If Me.YourMainFormControlName <>_
Me.YourSubformName!YourSubformsControlName then
Msgbox "Values don't match!"
else
Docmd.Close acForm, Me.name
Endif


Thank you, your help is appreciated.

Do realize that if there are no records in you subform it will probably
error.
If Me.YourSubformName.Form.Recordcount > 0 then...
'do your check
endif

Also, if you have an X button, it will run your code and close as well.
If a record exists, you can cancel the Unload. If it's a new record I
don't think there's a built in way to determine the X was trapped, so
you'd get the error message and then it would close.

Disable the close button on the form and create a command button to close the
form. You can then run whatever checks you want and if they fail, just cancel
the event. If the checks are OK then DoCms.Close acform, "EmpForm"
Phil

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.