By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

Cancel OnClose event when switching to design view

P: 78
I have an OnClose function that opens a switchboard (SwitchOpen). This function is placed in numerous objects' (reports and forms) OnClose event, and works great. However, a very annoying occurrence happens: when I have an object open, then click Design View, the OnClose event triggers, causing the switchboard to open event though the object isn't truly "closed". What event should I place the SwitchOpen under so that it only fires when the object is truly closed and not just in design view?
Jul 30 '08 #1
Share this Question
Share on Google+
10 Replies


missinglinq
Expert 2.5K+
P: 3,532
In point of fact, you are closing the form when you switch to Design View. Access also considers the form to be UnLoading when this happens, so moving it here won't help either. I'm not sure you can do anything except remark out the line opening the switchboard when you're developing the form, then un-remark it when you're ready to go into production. This is frequently done for situations just like this.

Linq ;0)>
Jul 30 '08 #2

NeoPa
Expert Mod 15k+
P: 31,263
I agree with Linq here I'm afraid. The object is closed when you switch to design view.

However, you may want to play with the following procedure call to see if you can determine whether or not the item is open at the time your code would otherwise start the switchboard.
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.SelectObject(ObjectType:=acForm, _
  2.                         ObjectName:={YourObjName}, _
  3.                         InDatabaseWindow:=False)
Aug 5 '08 #3

NeoPa
Expert Mod 15k+
P: 31,263
You'll need to use On Error code I suspect, and probably inspect the Err object immediately after the call.

Let us know if this helps and how you get on with it.
Aug 5 '08 #4

P: 78
Thanks NeoPa. I'm play aroud with that (as times permits!).
Aug 5 '08 #5

NeoPa
Expert Mod 15k+
P: 31,263
No worries. Always a pleasure :)

Come back if you need more help.
Aug 5 '08 #6

P: 2
I ran into this EXACT same problem today. One of the reasons I think I used to program in VB and use Access as a Back-end instead of using Access as a programming environment.... Of course, where I am now, I am stuck with Access only. One workaround is to disable the Close button of the form, use your own command button instead. On the Click event of the command button, set a form level control variable = TRUE. Then use the value of that variable to branch in the Unload or Close event according to whether you want to call the switchboard form or not. If the user enters design view (bypasses the command button), the value of the variable will be FALSE ... so this code in the Unload event will achieve what you want:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2. If mbFormControl Then 
  3.    doCmd.OpenForm "frm_Switchboard"
  4. End If
  5. End Sub
Oct 2 '08 #7

NeoPa
Expert Mod 15k+
P: 31,263
Hi Bill. Welcome to Bytes!

I would just make a quick suggestion referring to your idea of disabling the close button. Generally it's not necessary.

If, instead of putting code in the Event Procedure of your exit button, you put the code instead in the Form_Close() Event Procedure, and simply call Me.Close in the Event Procedure of your exit button, then all methods of terminating your form will be fully handled.

Does that make sense?
Oct 2 '08 #8

FishVal
Expert 2.5K+
P: 2,653
Hello, gentlemen.

It maybe slightly cumbersome, but it is possible to use the following feature:
Form_Timer event in a form being opened (unlike Form_Open, Form_Load and Form_Current event) fires after a calling form has been closed or switched into design mode.
Form in design view unlike closed one could be referenced via Forms collection and thus distinguished.
So, the whole logic may be the following:
  • In Form_Close event handler SwitchBoard form is opened with form name in OpenArgs.
  • In SwitchBoard Form_Timer event handler Forms collection is being checked for presence of the form and, if that seems insufficient, Form.CurrentView property may be checked as well.

Regards,
Fish
Oct 2 '08 #9

P: 2
Hi Bill. Welcome to Bytes!

I would just make a quick suggestion referring to your idea of disabling the close button. Generally it's not necessary.

If, instead of putting code in the Event Procedure of your exit button, you put the code instead in the Form_Close() Event Procedure, and simply call Me.Close in the Event Procedure of your exit button, then all methods of terminating your form will be fully handled.

Does that make sense?
Hi NeoPa, it certainly does. I will make the change.

Bill
Oct 8 '08 #10

NeoPa
Expert Mod 15k+
P: 31,263
Very pleased to hear it Bill :)

Needless to say, I never have that problem any more.
Oct 8 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.