473,500 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DoCmd.SetWarnings WarningsOn/Off

53 New Member
Hi,

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
  1. DoCmd.SetWarnings WarningsOff
  2. DoCmd.OpenQuery "Query Name"
  3. DoCmd.SetWarnings WarningsOn
The final line that turns the warnings back on does not seem to be working. Have I done something incorrect here? Here is a sample code for one of my buttons that use this:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Private Sub cmdOK_Click()
  3.     DoCmd.SetWarnings WarningsOff
  4.     DoCmd.OpenQuery "*RS INIDP"
  5.     DoCmd.SetWarnings WarningsOn
  6.  
  7.     Dim SufDate As String
  8.     Dim Day As Integer
  9.     Dim Month As Integer
  10.     Dim Year As Integer
  11.  
  12.     Day = DatePart("d", (Date))
  13.     Month = DatePart("m", (Date))
  14.     Year = DatePart("yyyy", (Date))
  15.     SufDate = "(" & Month & "-" & Day & "-" & Year & ")"
  16.     DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "qryQuarterlySales", "C:\QuarterlySales" & SufDate & ".xls", False
  17.     MsgBox "The query has been exported to C:\QuarterlySales" & SufDate & ".xls", vbOKOnly
  18.     Call Shell("excel.exe C:\QuarterlySales" & SufDate & ".xls", 1)
  19.     DoCmd.Close acForm, "frmQuarterlySales"
  20. End Sub
  21.  
This button runs a make table query (i need the data to be static because it runs too slow from the server) and then exports a query to excel.

So how can I properly turn the warnings back on?
Aug 27 '08 #1
6 44380
PianoMan64
374 Recognized Expert Contributor
Hi,

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
  1. DoCmd.SetWarnings WarningsOff
  2. DoCmd.OpenQuery "Query Name"
  3. DoCmd.SetWarnings WarningsOn
The final line that turns the warnings back on does not seem to be working. Have I done something incorrect here? Here is a sample code for one of my buttons that use this:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Private Sub cmdOK_Click()
  3.     DoCmd.SetWarnings WarningsOff
  4.     DoCmd.OpenQuery "*RS INIDP"
  5.     DoCmd.SetWarnings WarningsOn
  6.  
  7.     Dim SufDate As String
  8.     Dim Day As Integer
  9.     Dim Month As Integer
  10.     Dim Year As Integer
  11.  
  12.     Day = DatePart("d", (Date))
  13.     Month = DatePart("m", (Date))
  14.     Year = DatePart("yyyy", (Date))
  15.     SufDate = "(" & Month & "-" & Day & "-" & Year & ")"
  16.     DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "qryQuarterlySales", "C:\QuarterlySales" & SufDate & ".xls", False
  17.     MsgBox "The query has been exported to C:\QuarterlySales" & SufDate & ".xls", vbOKOnly
  18.     Call Shell("excel.exe C:\QuarterlySales" & SufDate & ".xls", 1)
  19.     DoCmd.Close acForm, "frmQuarterlySales"
  20. End Sub
  21.  
This button runs a make table query (i need the data to be static because it runs too slow from the server) and then exports a query to excel.

So how can I properly turn the warnings back on?
The reason that it isn't coming back on is because your syntax for the Warnings off and Warnings On are incorrect.

The proper syntax is:

Expand|Select|Wrap|Line Numbers
  1. Docmd.SetWarnings Off
  2. Docmd.SetWarnings On
  3.  
Hope that helps,

Joe P.
Aug 27 '08 #2
RZ15
53 New Member
The reason that it isn't coming back on is because your syntax for the Warnings off and Warnings On are incorrect.

The proper syntax is:

Expand|Select|Wrap|Line Numbers
  1. Docmd.SetWarnings Off
  2. Docmd.SetWarnings On
  3.  
Hope that helps,

Joe P.
Weird that it works for Off and not On though...

I will try this.
Aug 27 '08 #3
PianoMan64
374 Recognized Expert Contributor
Weird that it works for Off and not On though...

I will try this.
that reason is both values are Zero. So they both mean false or off.

That is why.

Hope that helps,

Joe P.
Aug 27 '08 #4
missinglinq
3,532 Recognized Expert Specialist
And actually, the correct syntax, per Access, is

DoCmd.SetWarnings False

and

DoCmd.SetWarnings True

As you've found out, incorrect syntax will sometimes, accidentally, work, but not always!

Linq ;0)>
Aug 27 '08 #5
nico5038
3,080 Recognized Expert Specialist
It's better to use:
Expand|Select|Wrap|Line Numbers
  1. currentdb.execute (strSQL)
  2.  
as this won't trigger a message and also won't turn off all the system messages as the DoCmd.SetWarnings will do after a failing query!

Nic;o)
Aug 28 '08 #6
NeoPa
32,557 Recognized Expert Moderator MVP
Weird that it works for Off and not On though...

I will try this.
Boolean values (True; False; Yes; No) are naturally two state items, but in Access (VBA) they are stored in numeric variables.

The values used to represent True and False are -1 and 0 respectively (each bit in the value is set to reflect the value required).

As, in real life, these variables can store more than simply those two values, there is a convention on how to handle values that are neither. The convention is to treat any non-zero value as True (or True if ANY bit is True).

If you have variables that are not declared (shame - always use Option Explicit - but that's another story) On; Off; WarningsOn; WarningsOff; etc, then these will be initialised by the compiler to zero. Zero is equivalent to False, so all of these undefined variables would be equivalent to False, giving exactly the results you're experiencing.

Does that help?
Aug 30 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
8025
by: deko | last post by:
This code is behind a button that exports the contents of a query ("qryXL_Tx") to an Excel spreadsheet. It works fine the first time, but will not run a second time. When I go to look at my...
3
17168
by: jj | last post by:
I've got a form button that fires off 3 queries but if the first query returns an error, I don't want the other two queries to happen. Example: first query runs an insert from a linked table but...
8
11200
by: RC | last post by:
In my Access 2002 form, I have a combo box and on the AfterUpdate event I use DoCmd.RunSQL ("UPDATE .... to update records in a table. When it starts to run I get a message "You are about to...
10
7176
by: MLH | last post by:
I thought I could run docmd.SetWarnings in the immediate window with no argument and A97 would return True or False, depending on the current setting. I was wrong. Anybody know how to make the...
12
5865
by: Pradeep Varma | last post by:
Hello, I am suppressing the warnings in Ms Access database by using the DoCmd.SetWarnings=False statement. However I want to get a list of all the Warnings that were generated between a: ...
1
6250
by: Simon | last post by:
Dear reader, With the DoCmd.OutputTo ...... you have the possibility to write a report to an external location. In case the external location is an existing file the DoCmd is not...
1
3043
by: natural | last post by:
Good Afternoon I have an option grou[ and on the after update i would like to provide the user with a msgbox, and then action placed my docmd.setwarnings false everywhere, but i still get my...
10
49580
by: Dean | last post by:
My client has a db I am working that uses temp tables. During an update procedure, I had the code If fTableExists(tempTblName) = True Then DoCmd.DeleteObject acTable, tempTblName Then I thought...
4
6630
by: gazza10001 | last post by:
Hi i hope you can help my company uses access and has modified for its needs usually what happens is you serach for the invoice by its number and then it brings all the information up such as...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.