Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.Close assumptions when using Button Wizard 1

Status
Not open for further replies.

uscitizen

Technical User
Jan 17, 2003
672
US
when i create a 'Close Form' button using the Button Wizard it generated a bunch of code that I have pasted for reference:
-------------------------------------------------------
Option Compare Database

Private Sub Command14_Click()
On Error GoTo Err_Command14_Click


DoCmd.Close

Exit_Command14_Click:
Exit Sub

Err_Command14_Click:
MsgBox Err.Description
Resume Exit_Command14_Click

End Sub
----------------------------------------------------------

above.

According to the Help documentation wrt the 'Close' method of the DoCmd, 'acSavePrompt' when the 'acSavePrompt' argument is left blank is the 'default'.

Well, as you can see in the above, it is left blank, yet there's no prompting when the button is clicked. The behavior I get when I click the 'Close Form' button is that my work is saved and the form closes.

Am I missing something? Can someone help explain?
 
Two possibilities that I can think of:

1)The form is being saved prior to the close being selected therefore there is nothing to save.

2)You might have the Setwarnings method set to false, if this is the case the form will be saved without the prompt, you would simply have to set it back to true before closing the form.

Hope this helps.

Regards,
gkprogrammer
 
well......

i created a blank database, a table and a form based on the table in it and a 'close form' command button to close the form via the command button wizard. the vba code's essentially the same as the one i posted before and there's no prompting from the user requested.

still scratching my head.
 
Are you expecting to get prompted when data on the form change? That won't happen. The prompt here is for design changes to the form. Maybe that's the confusion?

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
uhhuh, i was under the impression that it would prompt the user over saving data entry changes to the form --

is this to say that there's no way to do that?

 
Plenty of ways, but not that one.

Look into the "dirty" property of the form in the help files. You can try to react to that before moving to another record or closing the form.

The best way, though, is to get into the world of unbound forms. Using unbound forms means creating a recordset that gathers the data for the record, filling each of the controls, all using code. Then, when the user mnoves to another record, saves the record, or closes the form, you write sql to update the record, only executing it i the user indicates the desire to save. it's more work, for sure, but _much_ more secure.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
so, if i understand correctly, the DoCmd.Close operation closes the form and saves the information to the table underlying it. under the 'dirty' property HELP you told me about, i found a snippet of code which seems to do what i want.

thanks!
 
....just following up with a quick postscript:
there's a line in the code that stipulates that it's just For each control however the If clause tests only If ctlC.ControlType = acTextbox before restoring ctlC.Value = ctlC.OldValue.

my question is, is there a way to make this exhaustively search for changes made to any and all types of controls on the form; typically i use combo boxes, checkbuttons and or course text boxes?
 
a bound form's dirty property will be true if data in any control on that form has been modified.

I can't see the code you're talking about, so I'm not sure how to respond to the specifics of your question.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
hi!

okay, here's what's happening:

i found some code in the Dirty Event - Event Procedures Example which I'm modifying.

I placed this code in the 'On Dirty' event form property:


Private Sub Form_Dirty(Cancel As Integer)
If Me.Dirty Then
Me!btnUndo.Enabled = Enable 'Enable button
Else
Me!btnUndo.Enabled = Disable 'Disable button
End If
End Sub


then I placed this code in the 'On click' event property of a command button I set on the screen called 'Undo Changes':

Sub btnUndo_Click()
Dim C As Control
'Check each data entry control for change and record
'old value of Control.
For Each C In Me.Controls

'Only check data entry type controls.
Select Case C.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox, acToggleButton
If C.Name <> &quot;Updates&quot; Then
'Restore Old Value
C.Value = C.OldValue
End If
End Select
Next C
End Sub

At this point, I think I'm beyond the questin in my email above wrt the control types and testing for changes in each, however, a funny thing happens when I make a change in a control, the 'Undo Changes' button gets Disabled?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top