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: - DoCmd.SetWarnings WarningsOff
-
DoCmd.OpenQuery "Query Name"
-
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: -
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
-
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?
6 44415
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: - DoCmd.SetWarnings WarningsOff
-
DoCmd.OpenQuery "Query Name"
-
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: -
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
-
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: -
Docmd.SetWarnings Off
-
Docmd.SetWarnings On
-
Hope that helps,
Joe P.
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: -
Docmd.SetWarnings Off
-
Docmd.SetWarnings On
-
Hope that helps,
Joe P.
Weird that it works for Off and not On though...
I will try this.
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.
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)> nico5038 3,080
Recognized Expert Specialist
It's better to use: -
currentdb.execute (strSQL)
-
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)
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?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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"
|
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:
|
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?
|
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?
|
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.
| |
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
|
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
|
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.
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |