Disable Code If Form Loses Focus

D

Del

I have a main form that has a number of fields that are populated by
the user. The fields in questions are

1) RGAID - Auto Number - Primary Key
2) RGANbr
3) OrderEnteredBy
4) ClosedDate


Step 1:
In the On Exit event of the first user field in the main form called
"RGANbr" I have code that checks the table to see if the data the user
just entered already exist in the table with a different RGAID and the
ClosedDate is null. If it does already exist a popup form opens
displaying the data for this / these records (NOTE: The current RGAID
is excluded from being dispalyed). The user now has a choice to either
click on a button labeled "Continue" which simply closes the popup and
allows the user to complete the new record, or they can click on any
of the existing records display in the popup form and display the
record that already exist so they can edit that record.

Step 2:
The second user field on the main form is called "OrderEnteredBy", and
in the On Exit event of this field I have code that say if the
"RGANbr" field is populated the user MUST enter data in the
"OrderEnterBy" field.

The problem I am running into is when the pop up form is displayed in
Step 1: and the user clicks on one of the exisitng records displayed
in the popup to edit it, they recieve the message box from the On Exit
code of the "OrderEnteredBy" field on the main form.

Is there a way to disable the On Exit code of the "OrderEnteredBy"
field if the popup form is open?

Thank you!
 
S

Steve Schapel

Del,

I would handle this by having the focus move somewhere other that
OrderEnteredBy after it leaves RGANbr.

One fairly slick way you can do this is put a Command Button on the
form, and set its Transparent property to Yes. Then use the Tab Order
function of the form to insert this in the tab order between RGANbr and
OrderEnteredBy.

Then, when your popup form is open, the focus will be on this ghostly
command button.

If the user selects 'Continue' you can include code there such as:
Forms!YourMainForm!OrderEnteredBy.SetFocus

If, on the other hand, they select to go to an existing record, the
focus will not be on the OrderEnteredBy control, and therefore its Exit
event will not occur.

Hope I have understood the situation correctly.
 
D

Del

Del,

I would handle this by having the focus move somewhere other that
OrderEnteredBy after it leaves RGANbr.

One fairly slick way you can do this is put a Command Button on the
form, and set its Transparent property to Yes.  Then use the Tab Order
function of the form to insert this in the tab order between RGANbr and
OrderEnteredBy.

Then, when your popup form is open, the focus will be on this ghostly
command button.

If the user selects 'Continue' you can include code there such as:
Forms!YourMainForm!OrderEnteredBy.SetFocus

If, on the other hand, they select to go to an existing record, the
focus will not be on the OrderEnteredBy control, and therefore its Exit
event will not occur.

Hope I have understood the situation correctly.

--
Steve Schapel, Microsoft Access MVP










- Show quoted text -

Thanks Steve,
Don't know why I didn't think of that. I guess I was trying to make it
to difficult.
Thanks again!
Del
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top