I want a data editing form to check for changes when the close button is
pressed by the user. The code I have entered reads "Run time error 13. Type
Mismatch" Any help would be greatly appreciated!
Private Sub Form_Close()
If Me.DataChange Then
Dim strMsg As String
Dim Cancel As Integer
strMsg = "Data has changed."
strMsg = strMsg & " Do you wish to save the changes?"
strMsg = strMsg & " Click Yes to Save or No to Discard changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes
Then
'do nothing
Else
Me.Undo
Cancel = True
End If
Else
'do nothing
End If
End Sub
|
|
0
|
|
|
|
Reply
|
Utf
|
1/3/2008 6:06:02 PM |
|
"Travis (New User)" <TravisNewUser@discussions.microsoft.com> wrote in
message news:10E0C7AC-54B4-4909-B921-CF7975BD1C7B@microsoft.com...
>I want a data editing form to check for changes when the close button is
> pressed by the user. The code I have entered reads "Run time error 13.
> Type
> Mismatch" Any help would be greatly appreciated!
>
> Private Sub Form_Close()
>
> If Me.DataChange Then
> Dim strMsg As String
> Dim Cancel As Integer
> strMsg = "Data has changed."
> strMsg = strMsg & " Do you wish to save the changes?"
> strMsg = strMsg & " Click Yes to Save or No to Discard changes."
> If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes
> Then
> 'do nothing
> Else
> Me.Undo
> Cancel = True
> End If
> Else
> 'do nothing
> End If
> End Sub
Use the form's Unload event instead of its Close event. Notice that the
Unload event has a parameter called Cancel. Because that's supplied by
Access, you should delete the line:
Cancel = True
|
|
0
|
|
|
|
Reply
|
Stuart
|
1/3/2008 6:23:37 PM
|
|
New User Travis wrote:
> I want a data editing form to check for changes when the close button is
> pressed by the user. The code I have entered reads "Run time error 13. Type
> Mismatch" Any help would be greatly appreciated!
>
> Private Sub Form_Close()
>
> If Me.DataChange Then
> Dim strMsg As String
> Dim Cancel As Integer
> strMsg = "Data has changed."
> strMsg = strMsg & " Do you wish to save the changes?"
> strMsg = strMsg & " Click Yes to Save or No to Discard changes."
> If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes
> Then
> 'do nothing
> Else
> Me.Undo
> Cancel = True
> End If
> Else
> 'do nothing
> End If
> End Sub
Don't know much about VB, after only a week or so coding, but
sometimes this occurs when you mix and match strings and numbers on
the same line. Use the CStr() convert function to convert numbers to
strings and the corresponding cast for strings to numbers.
RL
|
|
0
|
|
|
|
Reply
|
raylopez99
|
1/3/2008 6:30:44 PM
|
|
"Stuart McCall" <smccall@myunrealbox.com> wrote in message
news:flj97n$4ko$1$830fa79d@news.demon.co.uk...
> "Travis (New User)" <TravisNewUser@discussions.microsoft.com> wrote in
> message news:10E0C7AC-54B4-4909-B921-CF7975BD1C7B@microsoft.com...
>>I want a data editing form to check for changes when the close button is
>> pressed by the user. The code I have entered reads "Run time error 13.
>> Type
>> Mismatch" Any help would be greatly appreciated!
>>
>> Private Sub Form_Close()
>>
>> If Me.DataChange Then
>> Dim strMsg As String
>> Dim Cancel As Integer
>> strMsg = "Data has changed."
>> strMsg = strMsg & " Do you wish to save the changes?"
>> strMsg = strMsg & " Click Yes to Save or No to Discard changes."
>> If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") =
>> vbYes
>> Then
>> 'do nothing
>> Else
>> Me.Undo
>> Cancel = True
>> End If
>> Else
>> 'do nothing
>> End If
>> End Sub
>
> Use the form's Unload event instead of its Close event. Notice that the
> Unload event has a parameter called Cancel. Because that's supplied by
> Access, you should delete the line:
>
> Cancel = True
Sorry, that should read:
Because that's supplied by Access, you should delete the line:
Dim Cancel As Integer
|
|
0
|
|
|
|
Reply
|
Stuart
|
1/3/2008 6:32:30 PM
|
|
You don't say on which line the error occurs, but I am thinking the way you
are using Me.DataChange could be the problem. A form control will not
evaluate to a boolean expression. That is, if DataChange is a control. If
it is a user defined form property, then it should be cast as a boolean data
type.
--
Dave Hargis, Microsoft Access MVP
"Travis (New User)" wrote:
> I want a data editing form to check for changes when the close button is
> pressed by the user. The code I have entered reads "Run time error 13. Type
> Mismatch" Any help would be greatly appreciated!
>
> Private Sub Form_Close()
>
> If Me.DataChange Then
> Dim strMsg As String
> Dim Cancel As Integer
> strMsg = "Data has changed."
> strMsg = strMsg & " Do you wish to save the changes?"
> strMsg = strMsg & " Click Yes to Save or No to Discard changes."
> If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes
> Then
> 'do nothing
> Else
> Me.Undo
> Cancel = True
> End If
> Else
> 'do nothing
> End If
> End Sub
|
|
0
|
|
|
|
Reply
|
Utf
|
1/3/2008 7:15:03 PM
|
|
On Jan 3, 2:15=A0pm, Klatuu <Kla...@discussions.microsoft.com> wrote:
> You don't say on which line the error occurs, but I am thinking the way yo=
u
> are using Me.DataChange could be the problem. =A0A form control will not
> evaluate to a boolean expression. =A0That is, if DataChange is a control. =
=A0If
> it is a user defined form property, then it should be cast as a boolean da=
ta
> type.
> --
> Dave Hargis, Microsoft Access MVP
Yes, Klatuu is right.
I was going to say the same thing the first time. For example, before
some helpful posters pointed out the correct syntax, the below used to
always give me this error:
'CORRECT SYNTAX:
If Not IsNull(Me.StockSymbol) Then
Str002G =3D Me.AcctID.Value
If Not IsNull(Me.AcctID) Then
Str001G =3D Me.StockSymbol.Value
End If
End If
replaces (THIS GIVES A RUN TIME ERROR OF "Type 13"--among other
errors):
If (Me.StockSymbol.Text <> Null And Me.AcctID.Text <> Null ) Then
=2E..
End If
|
|
0
|
|
|
|
Reply
|
raylopez99
|
1/3/2008 7:48:23 PM
|
|
This is not really a data type issue:
If (Me.StockSymbol.Text <> Null And Me.AcctID.Text <> Null ) Then
It is a syntax issue. Nothing will ever = Null or be <> Null. Even Null =
Null will return false. The only way to check for Null is:
If Not IsNull(Me.StockSymbol) And Not IsNull(Me.AcctID) Then
In this context, don't use the Text property. It is only valid when a
control has the focus.
--
Dave Hargis, Microsoft Access MVP
"raylopez99" wrote:
> On Jan 3, 2:15 pm, Klatuu <Kla...@discussions.microsoft.com> wrote:
> > You don't say on which line the error occurs, but I am thinking the way you
> > are using Me.DataChange could be the problem. A form control will not
> > evaluate to a boolean expression. That is, if DataChange is a control. If
> > it is a user defined form property, then it should be cast as a boolean data
> > type.
> > --
> > Dave Hargis, Microsoft Access MVP
>
> Yes, Klatuu is right.
>
> I was going to say the same thing the first time. For example, before
> some helpful posters pointed out the correct syntax, the below used to
> always give me this error:
>
> 'CORRECT SYNTAX:
>
> If Not IsNull(Me.StockSymbol) Then
> Str002G = Me.AcctID.Value
> If Not IsNull(Me.AcctID) Then
> Str001G = Me.StockSymbol.Value
> End If
> End If
>
> replaces (THIS GIVES A RUN TIME ERROR OF "Type 13"--among other
> errors):
>
> If (Me.StockSymbol.Text <> Null And Me.AcctID.Text <> Null ) Then
>
> ...
>
> End If
>
>
|
|
0
|
|
|
|
Reply
|
Utf
|
1/3/2008 8:00:03 PM
|
|
On Thu, 3 Jan 2008 10:06:02 -0800, Travis (New User)
<TravisNewUser@discussions.microsoft.com> wrote:
>I want a data editing form to check for changes when the close button is
>pressed by the user. The code I have entered reads "Run time error 13. Type
>Mismatch" Any help would be greatly appreciated!
>
>Private Sub Form_Close()
>
> If Me.DataChange Then
What is DataChange? A control on your form, or a custom form property that you
have created?
Because it's not a builtin Access feature, to my knowledge.
Do you perhaps mean Me.Dirty (a Boolean indicating that the user has changed
some value in a bound control on the form)?
John W. Vinson [MVP]
|
|
0
|
|
|
|
Reply
|
John
|
1/3/2008 11:25:38 PM
|
|
Alright guys, thanks for all the help. All of your answers put me in the
right direction. I didn't do a very good job explaining exactly what I
wanted, but here is the code that I came up with after all of your
suggestions that works:
If Me.Dirty Then
Dim strMsg As String
strMsg = "Data has changed."
strMsg = strMsg & " Do you wish to save the changes?"
strMsg = strMsg & " Click Yes to Save or No to Discard changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes
Then
'do nothing
DoCmd.Close
Else
Me.Undo
DoCmd.Close
End If
Else
'do nothing
DoCmd.Close
End If
On a form I have a close button, a save button, text boxes, drop down lists,
etc etc. I have taken away the microsoft given buttons at the top. The only
way for the user to interact with the form is by the objects I have given
them.
I wanted the save button to save the record automatically with no prompting,
but I wanted the exit button to check if there were any accidental changes
and ask the user to confirm what they wanted.
Again, thanks for all the help guys. You all got me on the right path!
- Travis
"Travis (New User)" wrote:
> I want a data editing form to check for changes when the close button is
> pressed by the user. The code I have entered reads "Run time error 13. Type
> Mismatch" Any help would be greatly appreciated!
>
> Private Sub Form_Close()
>
> If Me.DataChange Then
> Dim strMsg As String
> Dim Cancel As Integer
> strMsg = "Data has changed."
> strMsg = strMsg & " Do you wish to save the changes?"
> strMsg = strMsg & " Click Yes to Save or No to Discard changes."
> If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes
> Then
> 'do nothing
> Else
> Me.Undo
> Cancel = True
> End If
> Else
> 'do nothing
> End If
> End Sub
|
|
0
|
|
|
|
Reply
|
Utf
|
1/4/2008 3:27:02 PM
|
|
For your save button:
If Me.Dirty Then
Me.Dirty = False
End If
For your Exit Button, just use Docmd.Close in the click event. Put the code
to check for changes in the Form's Unload event. That way, if the user
closes the form either using the exit button or by some other means, it will
stilll do the check.
Put this in the Form Unload event:
Dim str Msg As String
If Me.Dirty Then
strMsg = "Data has changed."
strMsg = strMsg & " Do you wish to save the changes?"
strMsg = strMsg & " Click Yes to Save or No to Discard changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
Me.Dirty = False
Else
Me.Undo
End If
End If
--
Dave Hargis, Microsoft Access MVP
"Travis (New User)" wrote:
> Alright guys, thanks for all the help. All of your answers put me in the
> right direction. I didn't do a very good job explaining exactly what I
> wanted, but here is the code that I came up with after all of your
> suggestions that works:
>
> If Me.Dirty Then
> Dim strMsg As String
> strMsg = "Data has changed."
> strMsg = strMsg & " Do you wish to save the changes?"
> strMsg = strMsg & " Click Yes to Save or No to Discard changes."
> If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes
> Then
> 'do nothing
> DoCmd.Close
> Else
> Me.Undo
> DoCmd.Close
> End If
> Else
> 'do nothing
> DoCmd.Close
> End If
>
> On a form I have a close button, a save button, text boxes, drop down lists,
> etc etc. I have taken away the microsoft given buttons at the top. The only
> way for the user to interact with the form is by the objects I have given
> them.
>
> I wanted the save button to save the record automatically with no prompting,
> but I wanted the exit button to check if there were any accidental changes
> and ask the user to confirm what they wanted.
>
> Again, thanks for all the help guys. You all got me on the right path!
>
> - Travis
>
>
>
> "Travis (New User)" wrote:
>
> > I want a data editing form to check for changes when the close button is
> > pressed by the user. The code I have entered reads "Run time error 13. Type
> > Mismatch" Any help would be greatly appreciated!
> >
> > Private Sub Form_Close()
> >
> > If Me.DataChange Then
> > Dim strMsg As String
> > Dim Cancel As Integer
> > strMsg = "Data has changed."
> > strMsg = strMsg & " Do you wish to save the changes?"
> > strMsg = strMsg & " Click Yes to Save or No to Discard changes."
> > If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes
> > Then
> > 'do nothing
> > Else
> > Me.Undo
> > Cancel = True
> > End If
> > Else
> > 'do nothing
> > End If
> > End Sub
|
|
0
|
|
|
|
Reply
|
Utf
|
1/4/2008 3:35:01 PM
|
|
On Jan 4, 10:35=A0am, Klatuu <Kla...@discussions.microsoft.com> wrote:
> For your save button:
>
> =A0 =A0 If Me.Dirty Then
> =A0 =A0 =A0 =A0 Me.Dirty =3D False
> =A0 =A0 End If
>
> For your Exit Button, just use Docmd.Close in the click event. =A0Put the =
code
> to check for changes in the Form's Unload event. =A0That way, if the user
> closes the form either using the exit button or by some other means, it wi=
ll
> stilll do the check.
>
> Put this in the Form Unload event:
Very interesting thread but I have a newbie question--I understand the
principle behind Save in Windows, but in Access it seems that clicking
on the red "X" in the upper right corner always saves the record
automatically. That is, for any form I've worked with to date (about
2 weeks of VB programming to be sure), it seems (maybe I'm wrong) that
no data has ever been lost this way (by simply closing the form as
described above).
In short, why bother with "save"--it's it the default to save
everything if a form/control is dirty?
RL
|
|
0
|
|
|
|
Reply
|
raylopez99
|
1/4/2008 5:13:46 PM
|
|
You are correct. closing the form or the application will save any changes.
There is no real good reason to use a save button. It is just that some
people are afraid they will save data they don't want to save.
--
Dave Hargis, Microsoft Access MVP
"raylopez99" wrote:
> On Jan 4, 10:35 am, Klatuu <Kla...@discussions.microsoft.com> wrote:
> > For your save button:
> >
> > If Me.Dirty Then
> > Me.Dirty = False
> > End If
> >
> > For your Exit Button, just use Docmd.Close in the click event. Put the code
> > to check for changes in the Form's Unload event. That way, if the user
> > closes the form either using the exit button or by some other means, it will
> > stilll do the check.
> >
> > Put this in the Form Unload event:
>
>
> Very interesting thread but I have a newbie question--I understand the
> principle behind Save in Windows, but in Access it seems that clicking
> on the red "X" in the upper right corner always saves the record
> automatically. That is, for any form I've worked with to date (about
> 2 weeks of VB programming to be sure), it seems (maybe I'm wrong) that
> no data has ever been lost this way (by simply closing the form as
> described above).
>
> In short, why bother with "save"--it's it the default to save
> everything if a form/control is dirty?
There is no real good reason to do this. It is just that some people are
afraid they will save data they don't want to save.
>
> RL
>
|
|
0
|
|
|
|
Reply
|
Utf
|
1/4/2008 5:22:02 PM
|
|
|
11 Replies
226 Views
(page loaded in 0.229 seconds)
Similiar Articles: "do you want to save changes" when I close outlook ...Checking Data Change on Close ... you make any change to a message you've received, Outlook needs to confirm that you want to keep those changes when you close ... Exit database on close of form - microsoft.public.access ...... www.InformationFutures.net Microsoft Office/Access MVP http://mvp.support ... Checking Data Change on Close - microsoft.public.access ... I want a data editing form to ... Saving records only with a button - microsoft.public.access.forms ...If I enter or change data on a record it ... different record, a new record, or close ... box to the user asking them to confirm the save: If MsgBox("Save Changes to ... How to remove a data-damaged PO from Open to closed? - microsoft ...... the missing info directly into the Open tables, then close the ... QuickBooks Support - Verify and rebuild your company data file... or 2) repair the transaction or 3 ... Project 2007 - Does changing the name of the project work ...Save & close file in MS Project 4 ... renaming the file through File > Save As did change the data ... I apprently need to contact MS support again. Are ... Modify sub to exit if password is incorrect - microsoft.public ...Checking Data Change on Close - microsoft.public.access ..... editing form to check for ... VB for Apps Sub Example Incorrect - Microsoft Support... Applications Help ... Recover live calendars? - microsoft.public.windows.live.mail ...It will not say Sign in below the Close X if ... Changes made in one location impact the other. If ... For Calendar support with account data you will need to contact ... Prompt user to save changes in a form - microsoft.public.access ...Access automatically saves any changes, whenever you close the ... is pretty >standard if an accidental change to data ... by default, users are not prompted to confirm changes ... Excel.EXE will not close... Only when database closes - microsoft ...... ways and cannot seem to get it to close ... Worksheets(1) For example, change ... you are observing: Excel won't close ... that opens an excel file, reads in the data ... Live mail won't start - microsoft.public.windows.live.mail ...Your calendar contains corrupt data that is forcing Windows Live Mail to close. ... SSL on an account, click on the 'Apply' button and confirm your changes ... XML vs SQL Server - microsoft.public.dotnet.languages.csharp ...And some of the answers I get confirm some things I ... IDataReader idr = cmd.ExecuteReader(); con.Close ... That's the whole point of interfaces - - the data changes ... Saving and exiting - microsoft.public.project... had, at one time, a problem with data ... the file menu options of save-close-exit in sequence to be sure that the open data ... problem in any other training or support ... PS2007: My Tasks View - Cannot Edit Actual or Remaining Duration ...Is there something I need to change in ... can change relates to assignment data ... updating work should get me close to what I need for duration. I wanted to confirm that ... Outlook Closing Spontaneously - microsoft.public.outlook.general ...Change Windows Update to only *notify* you of ... Outlook 2007 Closes Unexpectedly - Tech Support Guy ... up from the system tray icon that says "A data file did not close ... CHANGES TO A FORM WON'T SAVE - microsoft.public.access.forms ...Download a copy of JetComp.exe: http://support ... Access 97 won't save changes to form design view. - microsoft ... Close form without saving data - microsoft.public ... How Best to Disable <ESC> Key on Form - microsoft.public ...If the user does NOT confirm, then data remains as entered. ... If MsgBox(" Do you want to CLEAR changes ... pressing Escape key when doing a compact and close. Excel Changes not saving - microsoft.public.mac.office.excel ...Enter some data in a blank cell, then delete it. Then save and close the workbook. ... Excel not saving changes - Tech Support Forum Couple of my users ... How to prevent form from closing - microsoft.public.access.forms ...If you try to close the form with unwanted data through "X" button, >Cancel = True ... Typically if you want to ask the user a question to confirm saving changes etc. Filename field path display with mapped drive - microsoft.public ...... setting described in http://support ... the setting (you may need to close/restart Word and you will need to update the field to see the difference after a registry change. form confirmation page - microsoft.public.frontpage.client ...... view the confirmation page and then confirm ... You can then review the data and have a ... microsoft.public.access i make changes in forms and queries and when i close an ... Open, change, or close Outlook data files - Outlook - Office.comOpen, change, or close Outlook data files. Applies to: Microsoft Outlook 2010 ... about hidden folders in Windows, see Windows Help and Support. Change an Outlook Data ... Confirm Changes using the Before Update Event | Database Solutions ...This article concentrates on changes made to existing data, and ... Confirm Changes using the Before Update Event. When ... to a new/next record, or they try to close ... Open, change, or close Outlook data files - Outlook - Office.comOpen, change, or close Outlook data files. Applies to: Microsoft Office Outlook 2007 ... The .pst data file does not support read-only media such as CDs and DVDs. Do You Want to Save Your Changes? - GadgetopiaUser changes some form data. When this happens “form_dirty” is now ... throw away your changes and close the form.”; if(confirm(prompt)){ // Use synchronous ... Shutdown Changes for Outlook 2010... the user attempts to close it. This article describes the changes to ... providers to prevent data ... Outlook would like to confirm the user is really intending to close ... JavaScript Popup BoxesWhen a confirm box pops up, the user will have to click either "OK" or "Cancel" to ... accepted our terms of use and privacy policy. Copyright 1999-2012 by Refsnes Data. ACC2000: How to Prompt User to Save Changes to Record in a Form... form to prompt the user to confirm changes ... procedure checks to see if the data ... move to a different record or close the form, you are prompted to confirm ... UPS: Support - Shipping, Freight, Logistics and Supply Chain ...... m. (and sometimes later) to residences, and by close of ... attempt, only the sender of the package can change the ... With Quantum View Data - Inbound, you can see the UPS ... A simple solution for tracking changes to Access data | TechRepublicIT Support ... You might want to keep an audit trail of data input changes. ... Save the module as basAuditTrail and close the VBE. Attaching Logic to Data Using Data Macros in Access 2010 Applications... Microsoft Access 2010 to add support for data ... save the new named data macro as UpdateTotal, and then click Close. ... current update; if not, do not change ... 7/24/2012 9:18:28 PM
|