473,626 Members | 3,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DoCmd.SetWarnin gs 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 44415
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.SetWarnin gs False

and

DoCmd.SetWarnin gs 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.SetWarnin gs will do after a failing query!

Nic;o)
Aug 28 '08 #6
NeoPa
32,568 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
8043
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 query... it's blank! No SQL at all.... Any ideas why this sub is eating my query?? Private Sub cmdExportXL_Click() strXLfile = "Transactions_" & strTxType & strTxAcct & strQtr & strYr & ".xls"
3
17223
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 if for some reason a field is missing a value that's required, Access throws up an error. At that point I just want to end the process and notify them of the error so they can correct the data and try the process again. Here's my code:
8
11220
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 update 3 row(s)." Is there a way to prevent the message from popping up?
10
7203
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 determination in the immediate window?
12
5879
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: DoCmd.SetWarnings False and DoCmd.SetWarnings True Please Suggest.
1
6272
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 responding with the warning "File already exist". The file will be overwrite without any warning even with the DoCmd.Setwarnings True in
1
3072
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 "record has been deleted". Is i possilbe to please assist in where i am going wrong Private Sub RecOffLet_AfterUpdate() On Error GoTo Err_Handler
10
49596
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 of using: If fTableExists(tempTblName) = True Then CurrentDb.Execute "DROP TABLE " & tempTblName Is there an advantage to either? What really be cool is DROP TABLE deleted the table and I didn't have to compact the db so much.
4
6653
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 entry fields and so there is a button you press which then takes to through to a print preview of the invoice and you print out the invoice but recent ly this message ahs started appearing and does not allow you to view the print preview of the invoice...
0
8203
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8368
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8512
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5576
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2630
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 we have to send another system
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.