473,383 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,383 developers and data experts.

How to Close a Main Form Without Saving Changes of any Subforms

NeoPa
32,556 Expert Mod 16PB
Introduction :

This article relates to the long-standing (Since at least Access 2.0.) problem whereby a Form, used within a Subform of another (main) Form, will have any temporary and transient design changes made during the time the main Form is open and in use, saved away automatically to become the new design of the Form. This is rarely desirable, yet is something Access does for you without any way to specify you don't want it to. Typically, a Form designer wants the Form left just as they've chosen to save it themselves. Transient changes are intended only for the lifetime of the instance currently in use and should not be saved away to become the new design of the Form.

Examples :

Examples of the sort of changes that are typical in such scenarios include :
  1. The size of the window on opening the Form in Design view (More an irritation for the designer).
  2. The sort order of the data.
  3. Filtering.
  4. Sizes and positions of any controls within the Form.
  5. Formats of controls used to illustrate specific situations.
  6. Etc.
In truth, the number of possible changes that may occur while the Form is in use is only limited to the number and type of the controls used within it, and the number of changeable properties for each of those controls. That, and the properties of the Form itself.

Solution :

I have found a solution, that seems to work, which is to drop the Form itself from the Subform control at the point where the main Form is closed. As it is not associated at the time Access would otherwise generously save it for you (even though you don't require it), no design changes are saved away and you can comfortably use it again in the knowledge that it is exactly as it was last saved in Design view.

Supporting Code :

The following code can be used generically to close any Form or Report object in the knowledge that no design changes are made to any of the related objects, either accidentally or via Access' misguided generosity.

Expand|Select|Wrap|Line Numbers
  1. 'CloseMe() closes the Form or Report.  No data or design changes are saved here.
  2. Public Sub CloseMe(objMe As Object)
  3.     Dim intType As Integer
  4.     Dim ctlVar As Control
  5.  
  6.     With objMe
  7.         Select Case True
  8.         Case TypeOf objMe Is Form
  9.             intType = acForm
  10.             Call .Undo
  11.             For Each ctlVar In .Controls
  12.                 With ctlVar
  13.                     If .ControlType = acSubform Then
  14.                         Call .Form.Undo
  15.                         .SourceObject = ""
  16.                     End If
  17.                 End With
  18.             Next ctlVar
  19.         Case TypeOf objMe Is Report
  20.             intType = acReport
  21.         Case Else
  22.             Exit Sub
  23.         End Select
  24.         Call DoCmd.Close(ObjectType:=intType _
  25.                        , ObjectName:=.Name _
  26.                        , Save:=acSaveNo)
  27.     End With
  28. End Sub
  • Line #8 Detects if the object is a Form.
  • Lines #9 - #15 Clears any unsaved data changes and unloads Forms from all Subforms.
  • Lines #16 - #17 More straightforward for Reports. Simply flags as Report for later.
  • Lines #18 - #19 Ignores any other type of object passed.
  • Lines #21 - #23 Closes main Form without saving any design changes.
Sep 15 '13 #1
0 7766

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

Similar topics

3
by: Nathan | last post by:
I read an earlier post from Gary and answered by Peter Huang concerning closing one form and showing another. I need to do the same thing in my application, but the code Peter gave didn't work for...
2
by: laks | last post by:
Hi I'm opening an aspx page with javascript: window.showModalDialog("mypage.aspx", "", "status:no"); In mypage.aspx I've got a button which shall first save the displayed record in the C# code...
2
by: Ivan Jericevich | last post by:
I changed some bindings and made a real mess, I would like to close the project and reload from my last save. How do I close the project withot it saving in it's current state of mess.
2
by: ClearCut | last post by:
I have written a program in VB6 that opens an existing Word document and adds some text to the top of the document before printing it. Now I want to close the document without saving the changes. ...
9
JAMBAI
by: JAMBAI | last post by:
Hi, I have a MS Access form,and its recordsource is some search query. When I click the close button (not the X mark) what ever data I typed in the form field are saved into the database. ...
2
by: jmarcrum | last post by:
Hi everyone!! I have a problem. I have a form for entering new data. If the user clicks the button on my frmMain (cmdAdd), the form for entering new data appears. However, IF the user decides...
11
beacon
by: beacon | last post by:
Hi everybody, I'm using Access 2003 and I have a form that has a custom cmdClose button. When pressed, a message box appears asking if the user wants to go back to a previous form. The problem...
2
TheSmileyCoder
by: TheSmileyCoder | last post by:
I have a form, which I open in dialog mode, and through the openArgs I set some values in the form (in a new record) thus dirtying the form. The idea is then that the user should make a selection...
5
by: Adnan Chowdhury | last post by:
How to close two form without using Application.Exit() the FormObj.Close() doesnt work
1
by: lorax | last post by:
I am new to this. I am recreating a form from ACCESS 2000 in Access 2010. The problem is that ACCESS no longer allow one to close a form without saving it. Form: a search form that allows people...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.