Cancel datasheet design changes when closing form

D

deekaye

I am trying to undo any changes a user might make to the columns widths
or column positions with a form in datasheet view when the form get
closed. I know if I trigger the close event like
docmd.close acforms, me.name, acSaveNo
Then any changes are not saved. The problem is that I cannot run this
if a user closes a form themselves by clicking close [X]. Is there any
way that I can say don't save datasheet layout changs when the user
closes the form?
 
A

Allen Browne

The usual solution is to set the properties for the columns in the Open
event of the form. Then it doesn't matter what the user did last time, it
always opens in a consistent state.

Example:

Private Sub Form_Open(Cancel As Integer)
Me.RowHeight = -1

With Me.ClientNum
.ColumnHidden = False
.ColumnOrder = 1
.ColumnWidth = 864
End With

With Me.Surname
.ColumnHidden = False
.ColumnOrder = 2
.ColumnWidth = 2880
End With

With Me.Address
.ColumnHidden = False
.ColumnOrder = 4
.ColumnWidth = -2 'Set for visible text.
End With

RunCommand acCmdUnfreezeAllColumns
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top