I frequently have code in my forms that will turn warnings off, run make table queries, then turn warnings back on using the following code:
Expand|Select|Wrap|Line Numbers
- DoCmd.SetWarnings WarningsOff
- DoCmd.OpenQuery "Query Name"
- DoCmd.SetWarnings WarningsOn
Expand|Select|Wrap|Line Numbers
- Option Compare Database
- Private Sub cmdOK_Click()
- DoCmd.SetWarnings WarningsOff
- DoCmd.OpenQuery "*RS INIDP"
- DoCmd.SetWarnings WarningsOn
- Dim SufDate As String
- Dim Day As Integer
- Dim Month As Integer
- Dim Year As Integer
- Day = DatePart("d", (Date))
- Month = DatePart("m", (Date))
- Year = DatePart("yyyy", (Date))
- SufDate = "(" & Month & "-" & Day & "-" & Year & ")"
- DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "qryQuarterlySales", "C:\QuarterlySales" & SufDate & ".xls", False
- MsgBox "The query has been exported to C:\QuarterlySales" & SufDate & ".xls", vbOKOnly
- Call Shell("excel.exe C:\QuarterlySales" & SufDate & ".xls", 1)
- DoCmd.Close acForm, "frmQuarterlySales"
- End Sub
So how can I properly turn the warnings back on?