MS Access - close a form without saving design changes, acSaveNo doesn't work

I have a Front End / Back End application in MS Access and am having some performance issues when closing forms.

These forms are always saved until they are closed because in Form_Open

I am hiding some columns and editing the signature. Then when I close the form, it saves hidden columns and wastes a lot of time!

I've already made many settings changes in Access to optimize for FE / BE. But I still have problems with forms that persist until closed. It is really time consuming when saving an event. Using hide / edit columns command needs to save 20 seconds. No procedure takes 1 s or less, but my data is not saved.

How can I hide / edit these columns without having to save the form? Or how can I close the form without saving the structure changes?

Unfortunately Access does not have an event BeforeClose

, but in the event Close

or Unload

it saves before going to that sub, so I cannot cancel it to close it later in code.

Hide code:

'show all columns
For i = 1 To 8
    Form_Y_SubF_LP.Controls("Item_00" & i).ColumnHidden = False
    Form_Y_SubF_LP.Controls("Quantity_00" & i).ColumnHidden = False
    Form_Y_SubF_LP.Controls("DistributionEQ_00" & i).ColumnHidden = False
'Hide unnecessary columns
For i = 8 To ProtQuant + 1 Step -1
    Form_Y_SubF_LP.Controls("Item_00" & i).ColumnHidden = True
    Form_Y_SubF_LP.Controls("Quantity_00" & i).ColumnHidden = True
    Form_Y_SubF_LP.Controls("DistributionEQ_00" & i).ColumnHidden = True

'Change the caption of columns to the real name of each prototype
prot = DLookup("[Prototype]", "Y_Configurações", "[Program]= '" & ProgramName & "'")
For i = 0 To UBound(Split(prot, ";"), 1)
    Form_Y_SubF_LP.Controls("Item_00" & i).Properties("Caption") = "Item_" & Split(prot, ";")(i)
    Form_Y_SubF_LP.Controls("Quantity_00" & i).Properties("Caption") = "Quantity_" & Split(prot, ";")(i)
    Form_Y_SubF_LP.Controls("DistributionEQ_00" & i).Properties("Caption") = "DistributionEQ_" & Split(prot, ";")(i)



source to share

1 answer

A simple solution is to set Close Button = No

on the form properties sheet, then add a cmdCloseMe command button with this for the On Click event:

Private Sub cmdCloseMe_Click()
    DoCmd.Close acForm, Me.Name, acSaveNo
End Sub


If you want your form to display in a Datasheet view, you need to embed it in a subform control of another form and add a cmdCloseMe button to that form.



All Articles