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:
DoCmd.OpenQuery "download_records_clear", acNormal, acEdit (clears
a temp table)
DoCmd.OpenQuery "download_records", acNormal, acEdit (downloads
linked records)
DoCmd.OpenQuery "download_records_set", acNormal, acEdit (update
linked records d/l value)
Well if Query "download_records" doesn't go well, I don't want to do query
"download_records_set".
Is there some sort of error checking I can put in between those two lines?
Here's the complete code for that button:
------------------------------------------------------
Private Sub ImportWebFiles_Click()
Dim qryOption As Boolean
On Error GoTo Err_ImportWebFiles_Click
qryOption = Application.GetOption("Confirm Action Queries")
Application.SetOption "Confirm Action Queries", False
DoCmd.OpenQuery "download_records_clear", acNormal, acEdit
DoCmd.OpenQuery "download_records", acNormal, acEdit
DoCmd.OpenQuery "download_records_set", acNormal, acEdit
MsgBox "Records downloaded."
Application.SetOption "Confirm Action Queries", qryOption
Exit_ImportWebFiles_Click:
Exit Sub
Err_ImportWebFiles_Click:
MsgBox Err.Description
Application.SetOption "Confirm Action Queries", qryOption
DoCmd.SetWarnings True
Resume Exit_ImportWebFiles_Click
End Sub
------------------------------------------------------------ 3 17127
"jj" <jj@test.net> wrote in message
news:X1*******************@twister.rdc-kc.rr.com... 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: DoCmd.OpenQuery "download_records_clear", acNormal, acEdit
(clears a temp table) DoCmd.OpenQuery "download_records", acNormal, acEdit (downloads linked records) DoCmd.OpenQuery "download_records_set", acNormal, acEdit
(update linked records d/l value)
Well if Query "download_records" doesn't go well, I don't want to do
query "download_records_set".
Is there some sort of error checking I can put in between those two
lines?
Use the Execute method instead with the appropriate option.
Dim MyDB as Database
Set MyDB = CurrentDB
MyDB.Execute "download_records_clear", dbFailOnError
MyDB.Execute "download_records", dbFailOnError
MyDB.Execute "download_records_set", dbFailOnError
The dbFailOnError causes an Error event to be raised if the query fails.
Code execution should then revert to your error handler.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Hmmm.. it's giving me a User-defined Data Type Not Found error with:
Dim MyDB As Database
Set MyDB = CurrentDb
I didn't have to define a database connection before or anything, so what
would it be looking for here?
Thanks!
"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:bn************@ID-98015.news.uni-berlin.de... "jj" <jj@test.net> wrote in message news:X1*******************@twister.rdc-kc.rr.com... 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: DoCmd.OpenQuery "download_records_clear", acNormal, acEdit (clears a temp table) DoCmd.OpenQuery "download_records", acNormal, acEdit
(downloads linked records) DoCmd.OpenQuery "download_records_set", acNormal, acEdit (update linked records d/l value)
Well if Query "download_records" doesn't go well, I don't want to do query "download_records_set".
Is there some sort of error checking I can put in between those two lines?
Use the Execute method instead with the appropriate option.
Dim MyDB as Database Set MyDB = CurrentDB
MyDB.Execute "download_records_clear", dbFailOnError MyDB.Execute "download_records", dbFailOnError MyDB.Execute "download_records_set", dbFailOnError
The dbFailOnError causes an Error event to be raised if the query fails. Code execution should then revert to your error handler.
-- I don't check the Email account attached to this message. Send instead to... RBrandt at Hunter dot com
Nevermind I found that I had to select DAO 3.6 in Tools>References.
However, is there another way to work this so that setting doesn't have to
be made on other files, etc? Can .Execute only be used with DAO 3.6?
"jj" <jj@test.net> wrote in message
news:OZ*******************@twister.rdc-kc.rr.com... Hmmm.. it's giving me a User-defined Data Type Not Found error with:
Dim MyDB As Database Set MyDB = CurrentDb
I didn't have to define a database connection before or anything, so what would it be looking for here?
Thanks!
"Rick Brandt" <ri*********@hotmail.com> wrote in message news:bn************@ID-98015.news.uni-berlin.de... "jj" <jj@test.net> wrote in message news:X1*******************@twister.rdc-kc.rr.com... 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: DoCmd.OpenQuery "download_records_clear", acNormal, acEdit (clears a temp table) DoCmd.OpenQuery "download_records", acNormal, acEdit (downloads linked records) DoCmd.OpenQuery "download_records_set", acNormal, acEdit
(update linked records d/l value)
Well if Query "download_records" doesn't go well, I don't want to do query "download_records_set".
Is there some sort of error checking I can put in between those two lines?
Use the Execute method instead with the appropriate option.
Dim MyDB as Database Set MyDB = CurrentDB
MyDB.Execute "download_records_clear", dbFailOnError MyDB.Execute "download_records", dbFailOnError MyDB.Execute "download_records_set", dbFailOnError
The dbFailOnError causes an Error event to be raised if the query fails. Code execution should then revert to your error handler.
-- I don't check the Email account attached to this message. Send instead to... RBrandt at Hunter dot com
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jim |
last post by:
I am using Access 97 on a PC running Windows NT 4.0 SP6a.
I have some code (shown below) intended to add a set of records to one
table (tblGradeProps) when a new record is created in another...
|
by: tina |
last post by:
Hello,
I would really appreciate some help. I am still learning VBA and I
feel like my brain is fried already.
Below I am trying to run a query and do a loop.
I actually get the data set but...
|
by: Tyson |
last post by:
I have got this little piece of code that fires on exit of a text box.
It run's my query perfectly based of my form input. But I don't know
how to bring result in my query back to a text box on my...
|
by: DD |
last post by:
I have a form and in the OnOpen Event i have the following
DoCmd.OpenQuery "qryUpDatePayment"
This creates an error,,however i need to update the qry when i open the form
this is only occuring...
|
by: alingsjtu |
last post by:
Hello, every body.
When execute dynamic generated multiple OPENQUERY statements (which
linkes to DB2) in SQLServer, I always got SQL1040N The maximum number
of applications is already connected...
|
by: technocraze |
last post by:
Hi community experts,
May I know is it possible to display an error message or not opening a form or query when users provide with the wrong inputs in the DoCmd.OpenForm and DoCmd.OpenQuery...
|
by: teddysnips |
last post by:
My clients have asked me to maintain a database that was developed in-
house. It's pretty good, considering the developer isn't a
"programmer".
The first thing they want me to do is to split it...
|
by: RZ15 |
last post by:
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
| |