473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Cancel OnClose event when switching to design view

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
10 5823
missinglinq
3,532 Expert 2GB
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
32,556 Expert Mod 16PB
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
32,556 Expert Mod 16PB
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
kpfunf
78
Thanks NeoPa. I'm play aroud with that (as times permits!).
Aug 5 '08 #5
NeoPa
32,556 Expert Mod 16PB
No worries. Always a pleasure :)

Come back if you need more help.
Aug 5 '08 #6
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
32,556 Expert Mod 16PB
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
2,653 Expert 2GB
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
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
32,556 Expert Mod 16PB
Very pleased to hear it Bill :)

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

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

Similar topics

1
by: Matthew Wells | last post by:
I have a a parent form with a subform. The parent form has two command buttons to change the subform view to single form view and datasheet view respectively. I can't seem to get this to work. ...
1
by: Maverick | last post by:
in normal Window form programming, there's something like form_unload function. but in asp.net the Page_Unload function is obviously not serving the same purpose. Do you guys know how to get the...
4
by: Ian Kelly | last post by:
Hi All, I have an .net form that is split into two frames. The left frame has a tree that displays a list of all the customers. The right frame displays the appropriate clients information. ...
10
by: Andrew | last post by:
Hi, I have a messagebox that pops up due to an event. I did it in javascript. ie. alert("Time's up. Assessment Ended"); I want to capture the OK and Cancel events of this alert messagebox. My...
6
by: Luke Matuszewski | last post by:
As in topic... has anyone used it ? I tried to use it but i guess i failed... here is a code: <html> <head> <title></title> <script type="text/javascript"> function closedWin() {...
6
by: Peter M. | last post by:
Hi all, If an event has multiple subscribers, is it possible to cancel the invocation of event handlers from an event handler? Or to be more specific: I'm subscribing to the ColumnChanging...
2
by: Steve | last post by:
After running into a design wall with my traditional thread approach, I realized that a BackgroundWorker object would fit my needs pretty good. Never really used them before. In a nutshell, my...
2
by: ApexData | last post by:
I have a Single form with its RecordSource set to one table. This form will have only one record that is used for the application setup. I have UnBound TextBoxes on the form. The textboxes will...
0
by: Christian | last post by:
Hi all, i already posted this in dotnet.vb.controls but i need some help, so i cant wait... I have written a web control library and have some problems with it. The Library contains only two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.