473,698 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How NOT to save a form or report

PhilOfWalton
1,430 Recognized Expert Top Contributor
I use the following routine to open a form or report, check if there is an OnLoad event, if not I add it.

Experimentall I type
Expand|Select|Wrap|Line Numbers
  1. PP_OpenForm(2,"RptSeminarbesucher", acPreview)
  2.  
into the Debug Window

I then add a line of code to translate the form into a foreign language. All works perfectly ... nearly.

Expand|Select|Wrap|Line Numbers
  1. Function PP_OpenForm(FormOrReport As Integer, FormReportName As String, Optional StrView As String = acNormal, _
  2.     Optional StrFilterName As String, Optional StrWhereCondition As String, _
  3.     Optional varDataMode As Variant = acFormPropertySettings, _
  4.     Optional varWindowMode As Variant = acWindowNormal, Optional varOpenArgs As Variant)
  5.  
  6.     'PP_OpenForm(2,"RptSeminarbesucher", acPreview)
  7.  
  8.     Dim TypeOfObject As Object
  9.     Dim Mdl As Module
  10.     Dim StartLine As Long, EndLine As Long
  11.     Dim StartCol As Long, EndCol As Long
  12.     Dim Increment As Integer
  13.     Dim HasMdl As Boolean
  14.     Dim ModuleAdded As Boolean
  15.     Dim PP_LoadAdded As Boolean
  16.     Dim ProcLineCount As Long
  17.  
  18.     ' Opens a form and insert PP_Load me.Name into the On open Event
  19.  
  20.     If FormOrReport = 1 Then
  21.         DoCmd.OpenForm FormReportName, acDesign
  22.         Set TypeOfObject = Forms!FormReportName
  23.     Else
  24.         DoCmd.OpenReport FormReportName, acDesign
  25.         Set TypeOfObject = Reports(FormReportName)
  26.     End If
  27.  
  28.     HasMdl = TypeOfObject.HasModule             ' Save has module
  29.     If TypeOfObject.HasModule = 0 Then
  30.         TypeOfObject.HasModule = -1
  31.     End If
  32.  
  33.     Increment = 2
  34.  
  35.     Set Mdl = TypeOfObject.Module
  36.  
  37.     If FormOrReport = 1 Then                    ' Form
  38.         Mdl.Find "Form_Load", StartLine, StartCol, EndLine, EndCol
  39.         If StartLine = 0 Then                       ' Sub Form_Load not found
  40.             StartLine = Mdl.CreateEventProc("Load", "Form")
  41.             ModuleAdded = -1
  42.         End If
  43.     Else                                        ' Report
  44.         Mdl.Find "Report_Load", StartLine, StartCol, EndLine, EndCol
  45.         If StartLine = 0 Then
  46.             StartLine = Mdl.CreateEventProc("Load", "Report")
  47.         End If
  48.     End If
  49.  
  50.     Mdl.Find "PP_Load", StartLine, StartCol, EndLine, EndCol
  51.  
  52.     'StartLine = 0
  53.     If StartLine = 0 Then
  54.         Mdl.InsertLines StartLine + Increment, "    PP_Load " & Chr$(34) & TypeOfObject.name & Chr$(34)
  55.         PP_LoadAdded = -1
  56.     End If
  57.  
  58.     If FormOrReport = 1 Then
  59.         DoCmd.OpenForm FormReportName, StrView, StrFilterName, StrWhereCondition, varDataMode, varWindowMode, varOpenArgs
  60.     Else
  61.         DoCmd.OpenReport FormReportName, StrView, StrFilterName, StrWhereCondition, varWindowMode, varOpenArgs
  62.     End If
  63.  
  64. CleanUp:
  65.     DoEvents
  66.  
  67.     Exit Function
  68.  
  69. End Function
  70.  
The problem is when the form or report is closed I am prompted whether to save it. The answer is always "NO"

Now I do not want to modify any forms or reports so is there a way or preventing the question and just closing the form or report unchanged?

Phil
Oct 4 '17
10 3431
NeoPa
32,569 Recognized Expert Moderator MVP
Hi Phil.

I've attached a very quick and very basic database that illustrates what I was trying to say earlier. One Form, one Command Button on that Form. Simple as you like.

I include the code below :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private blnAllowClose As Boolean
  5.  
  6. Private Sub cmdClose_Click()
  7.     blnAllowClose = True
  8.     Call DoCmd.Close(ObjectType:=acForm, ObjectName:=Me.Name, Save:=acSaveNo)
  9. End Sub
  10.  
  11. Private Sub Form_Unload(Cancel As Integer)
  12.     Dim strMsg As String
  13.  
  14.     If Not blnAllowClose Then
  15.         Cancel = True
  16.         strMsg = "You may only close this form by clicking the Close button"
  17.         Call MsgBox(Prompt:=strMsg _
  18.                   , Buttons:=vbInformation Or vbOKOnly _
  19.                   , Title:=Me.Name)
  20.     End If
  21. End Sub
Please confirm this is what you were after.
Attached Files
File Type: zip PhilofWalton.ZIP (20.3 KB, 75 views)
Oct 15 '17 #11

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

Similar topics

1
2166
by: Scott Sabo | last post by:
I have a form & report based on a query which shows details about employees performance reviews (hire date, review date, review submital date, etc). We do 90 day probation reviews as well and I want to be able to indicate employees who have a hire date that is within 90 days of the current date and highlight their records in the form and report with a yellow background. How would this be best accomplished using DateDiff or DateAdd? ...
0
5380
by: ghadley_00 | last post by:
MS Access Create form / report with multiple pages using different background images Hi, Would like to have users fill out a multipage form, and then click a print button, which pulls up the info just entered for a particular record and print out multiple pages of forms, each page having a different image as background.
0
2558
by: ernxos | last post by:
Hi, There is a button on one of my www pages which changes page content. It adds some fields to the form, which is created by php script. After changing the page is displayed once again. What I want to do is to save form data so after changing and reloading the page field are filled. That button is not Submit button. Can I do such thing?
3
5916
by: Mac Campbell | last post by:
For some unknown reason my mdb seemed to drop a module I had named "Utilities". I tried to copy the module back in from a backup copy and got the error message "<<MyProject>> is currently unable to rename the form, report, or module to 'Utilities' ... Close the database, reopen it, and try the rename operation again." This didn't work. It seemed that other modules could still be renamed normally, but this one - "Utilities" - could not. I could...
2
2111
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I am using reporting service with asp.net. I want to save a report snapshot in some time. How do I do this in asp.net? Is there any web service to do this? Thanks in advance! -Billy
3
10874
by: MyWaterloo | last post by:
I am trying to open my purchase orders form and go to the last record. In the on open command I do: DoCmd.GoToRecord , , acLast Seems straight forward enough...but I keep getting this message "You entered an expression that has invalid reference to the property Form/Report" before the form opens. After I acknowledge the message the form opens and goes to the last record. How do I X the message.
2
2319
by: kimeee | last post by:
I have a form that faculty need to fill out but it is very long and some stop before they can finish it and then have to re-enter all the fields they previously populated. So my boss asked if there was a way to set up the form so there is a 'save form' button and a 'submit' button, so our faculty don't have to complete the form in one sitting. I accomplished this roughly using cookies but no 'save form' button. It does it all in the...
8
4115
Seth Schrock
by: Seth Schrock | last post by:
I'm creating a billing database and I'm wanting to be able to save the report that I use for the bill. I thought about using a Make Table query, but then you get a ton of tables. I could also export to PDF. My main problem is that I want a link to each bill in the customer form so that if a customer has a question about the bill, I can just pull up the customer's form and then click on the link to bring up the bill in question. I don't know...
3
14003
beacon
by: beacon | last post by:
Hi everybody, I'm using Access 2010, but the format for the database is .mdb because I'm not ready to fully convert it to Access 2010 and the .accdb format. I've been reading up on how to create Shortcut Menus in Access 2010 using VBA and I'm pretty confident I understand how most of it works...meaning that I can create a custom shortcut menu, register it (for lack of a better term) so it displays in a form's/report's shortcut menu...
2
4526
by: nalongar | last post by:
Hi! First off, bear with me; I've just started to learn VBA and this is my first post on this site. My question could be extremely basic, but I haven't been able to find anything via the internet that fits my needs exactly. I need a way to save a report to a specific path after I have printed it as a PDF, so that I can send it as an email attachment. The idea is that an associate would be able to press a button and the report would print...
0
8675
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8897
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8862
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7729
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.