Link to home
Start Free TrialLog in
Avatar of mainrotor
mainrotor

asked on

How do you turn off the warnings in Access 2013

Hi Experts,
I have the following code below to load data to a datasheet, but every time I close the form I get a warning message asking If I want to save changes to my queries.  I tried setting the warnings to off, but that didn't solve the issue.
How can I solve this issue?

Private Sub LoadAvailableTechs()
    DoCmd.SetWarnings False
    Dim pSQL As String

    pSQL = "SELECT * FROM Staging_Table ORDER BY Staging_Table.Tech_Name"
    
    Me.dataAvailabilitySubform.SourceObject = "Query.qryStagingTable"
    Me.dataAvailabilitySubform.Form.RecordSource = pSQL
    Me.dataAvailabilitySubform.Requery
      
    
    Me.dataAvailabilitySubform.Form.AllowEdits = True
    Me.dataAvailabilitySubform.Form.AllowAdditions = False
    Me.dataAvailabilitySubform.Form.AllowDeletions = False
    DoCmd.SetWarnings True
End Sub

Open in new window




Thanks in advance,
mrotor
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or do a close on the form explicitly using the arguments acSaveNo or acSaveYes.

 acSavePrompt is the default if not specified, which is the prompt you get when you go to close and there are changes.

 No will discard all changes, yes will save them without a prompt.

Jim.
As I recall it, that isn't enough for a datasheet.
If you rearrange colums, it will prompt you before closing.

/gustav
DoCmd.SetWarnings False is extremely dangerous.  When you use it in code to turn off warnings caused by Action queries, be certain to turn the warnings back on immediately after.  In fact, this setting is so dangerous that when ever I set warnings off, I set the hourglass on and vice versa.  This gives me a visual clue that my code to turn them back on was interrupted.

Leaving warnings off, can result in loss of changes to objects you modified in design view since if you close without specifically saving first, Access will silently discard your changes.