I have a form where, on the form's open event, it changes the properties of a subform query by hiding/showing a column, depending on the user's permission level:
Private Sub Form_Open(Cancel As Integer)
If IsUserInGroup("CostPrice") = True Then
[subDefaultBOM].Form.Controls("Standard Cost").Properties("ColumnHidden") = False
Else
[subDefaultBOM].Form.Controls("Standard Cost").Properties("ColumnHidden") = True
End If
End Sub
The problem is that when the user closes the form, it asks them if they want to save the changes that were made above:
I need it to either not ask to save or to just automatically save it, without bothering the user with this. What can I do here? I've already tried DoCmd.Save acForm, Me.Name
, but this didn't work because not only did it still ask me to save the changes to the subform query but also the main form.
The answer was to use a form subform, not a query subform. See MajP's answer here: https://www.access-programmers.co.uk/forums/threads/how-do-i-save-the-layout-of-a-subform-after-modifying-it-on-the-main-forms-on-open-event.334086/#post-1963627
You should not have to save or get this message. I do this all the time without any prompt. However it looks to me that your subform source object is a query object and not a form in datasheet. Make sure to use a datasheet form and your problem should go away. Also call the code in the on load event and not the on open event.