473,320 Members | 1,868 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,320 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 7757

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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.