473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need help desperately, Problem Generating Errors for currentdb.execute

Below is some code for doing and insert into one of my tables. The
inserts do not work because a duplicate key exists, which I want to
happen. The problem is, I cannot get access to return an error for this
condition.

What can I do to get access to return an error on my query?
Thanks

-------------------------------
CODE
-------------------------------

On Error GoTo sql_error_err

Set Mydb = CurrentDb
Mydb.Execute sql, dbFailOnError

sql_error_exit:
Exit Sub

sql_error_err:
MsgBox Err.Number
MsgBox Err.Description
Debug.Print Err.Description
Debug.Print Err.Description
Debug.Print Err.Source
Resume sql_error_exit
Nov 12 '05 #1
8 2482
If your back-end is Jet, that should work fine, though it will display the
same error message twice in the Immediate window. If you are using an ODBC
back-end, then you might need to loop through the Errors collection.

The only issue with the Errors collection is that it holds the last JET error
info even if a later non-JET error is what you're currently handling. The way
to check that is if the Errors collection has >=1 items, and the last item's
..Number is the same as Err.Number, then the Errors collection refers to the
current VB error.

On Wed, 28 Apr 2004 10:59:34 -0400, frank <zi***@zip.com> wrote:
Below is some code for doing and insert into one of my tables. The
inserts do not work because a duplicate key exists, which I want to
happen. The problem is, I cannot get access to return an error for this
condition.

What can I do to get access to return an error on my query?
Thanks

-------------------------------
CODE
-------------------------------

On Error GoTo sql_error_err

Set Mydb = CurrentDb
Mydb.Execute sql, dbFailOnError

sql_error_exit:
Exit Sub

sql_error_err:
MsgBox Err.Number
MsgBox Err.Description
Debug.Print Err.Description
Debug.Print Err.Description
Debug.Print Err.Source
Resume sql_error_exit


Nov 12 '05 #2
How many groups did you post this to?
Nov 12 '05 #3
Two groups.

Allen Browne wrote:
How many groups did you post this to?


Nov 12 '05 #4
I am pretty new to vba, I am not quite sure how to do what you are
explaining.

Steve Jorgensen wrote:
If your back-end is Jet, that should work fine, though it will display the
same error message twice in the Immediate window. If you are using an ODBC
back-end, then you might need to loop through the Errors collection.

The only issue with the Errors collection is that it holds the last JET error
info even if a later non-JET error is what you're currently handling. The way
to check that is if the Errors collection has >=1 items, and the last item's
.Number is the same as Err.Number, then the Errors collection refers to the
current VB error.

On Wed, 28 Apr 2004 10:59:34 -0400, frank <zi***@zip.com> wrote:

Below is some code for doing and insert into one of my tables. The
inserts do not work because a duplicate key exists, which I want to
happen. The problem is, I cannot get access to return an error for this
condition.

What can I do to get access to return an error on my query?
Thanks

-------------------------------
CODE
-------------------------------

On Error GoTo sql_error_err

Set Mydb = CurrentDb
Mydb.Execute sql, dbFailOnError

sql_error_exit:
Exit Sub

sql_error_err:
MsgBox Err.Number
MsgBox Err.Description
Debug.Print Err.Description
Debug.Print Err.Description
Debug.Print Err.Source
Resume sql_error_exit



Nov 12 '05 #5
A JET back-end means you're using a plain ol' MDB file, either the local MDB
or another MDB with links. ODBC means you're linked to some kind of SQL
server. Everything else you need to understand what I've written here, you
should be able to get by reading the help on the Errors collection.

On Wed, 28 Apr 2004 11:26:43 -0400, frank <zi***@zip.com> wrote:
I am pretty new to vba, I am not quite sure how to do what you are
explaining.

Steve Jorgensen wrote:
If your back-end is Jet, that should work fine, though it will display the
same error message twice in the Immediate window. If you are using an ODBC
back-end, then you might need to loop through the Errors collection.

The only issue with the Errors collection is that it holds the last JET error
info even if a later non-JET error is what you're currently handling. The way
to check that is if the Errors collection has >=1 items, and the last item's
.Number is the same as Err.Number, then the Errors collection refers to the
current VB error.

On Wed, 28 Apr 2004 10:59:34 -0400, frank <zi***@zip.com> wrote:

Below is some code for doing and insert into one of my tables. The
inserts do not work because a duplicate key exists, which I want to
happen. The problem is, I cannot get access to return an error for this
condition.

What can I do to get access to return an error on my query?
Thanks

-------------------------------
CODE
-------------------------------

On Error GoTo sql_error_err

Set Mydb = CurrentDb
Mydb.Execute sql, dbFailOnError

sql_error_exit:
Exit Sub

sql_error_err:
MsgBox Err.Number
MsgBox Err.Description
Debug.Print Err.Description
Debug.Print Err.Description
Debug.Print Err.Source
Resume sql_error_exit



Nov 12 '05 #6
No, it is a plain ol MDB file :)

Steve Jorgensen wrote:
A JET back-end means you're using a plain ol' MDB file, either the local MDB
or another MDB with links. ODBC means you're linked to some kind of SQL
server. Everything else you need to understand what I've written here, you
should be able to get by reading the help on the Errors collection.

On Wed, 28 Apr 2004 11:26:43 -0400, frank <zi***@zip.com> wrote:

I am pretty new to vba, I am not quite sure how to do what you are
explaining.

Steve Jorgensen wrote:

If your back-end is Jet, that should work fine, though it will display the
same error message twice in the Immediate window. If you are using an ODBC
back-end, then you might need to loop through the Errors collection.

The only issue with the Errors collection is that it holds the last JET error
info even if a later non-JET error is what you're currently handling. The way
to check that is if the Errors collection has >=1 items, and the last item's
.Number is the same as Err.Number, then the Errors collection refers to the
current VB error.

On Wed, 28 Apr 2004 10:59:34 -0400, frank <zi***@zip.com> wrote:

Below is some code for doing and insert into one of my tables. The
inserts do not work because a duplicate key exists, which I want to
happen. The problem is, I cannot get access to return an error for this
condition.

What can I do to get access to return an error on my query?
Thanks

-------------------------------
CODE
-------------------------------

On Error GoTo sql_error_err

Set Mydb = CurrentDb
Mydb.Execute sql, dbFailOnError

sql_error_exit:
Exit Sub

sql_error_err:
MsgBox Err.Number
MsgBox Err.Description
Debug.Print Err.Description
Debug.Print Err.Description
Debug.Print Err.Source
Resume sql_error_exit


Nov 12 '05 #7
Then what is it that's not working about your original code?

On Wed, 28 Apr 2004 11:41:52 -0400, frank <zi***@zip.com> wrote:
No, it is a plain ol MDB file :)

Steve Jorgensen wrote:
A JET back-end means you're using a plain ol' MDB file, either the local MDB
or another MDB with links. ODBC means you're linked to some kind of SQL
server. Everything else you need to understand what I've written here, you
should be able to get by reading the help on the Errors collection.

On Wed, 28 Apr 2004 11:26:43 -0400, frank <zi***@zip.com> wrote:

I am pretty new to vba, I am not quite sure how to do what you are
explaining.

Steve Jorgensen wrote:
If your back-end is Jet, that should work fine, though it will display the
same error message twice in the Immediate window. If you are using an ODBC
back-end, then you might need to loop through the Errors collection.

The only issue with the Errors collection is that it holds the last JET error
info even if a later non-JET error is what you're currently handling. The way
to check that is if the Errors collection has >=1 items, and the last item's
.Number is the same as Err.Number, then the Errors collection refers to the
current VB error.

On Wed, 28 Apr 2004 10:59:34 -0400, frank <zi***@zip.com> wrote:

>Below is some code for doing and insert into one of my tables. The
>inserts do not work because a duplicate key exists, which I want to
>happen. The problem is, I cannot get access to return an error for this
>condition.
>
>What can I do to get access to return an error on my query?
>
>
>Thanks
>
>-------------------------------
>CODE
>-------------------------------
>
>On Error GoTo sql_error_err
>
>Set Mydb = CurrentDb
>Mydb.Execute sql, dbFailOnError
>
>
>
>sql_error_exit:
> Exit Sub
>
>sql_error_err:
> MsgBox Err.Number
> MsgBox Err.Description
> Debug.Print Err.Description
> Debug.Print Err.Description
> Debug.Print Err.Source
> Resume sql_error_exit
>


Nov 12 '05 #8
frank <zi***@zip.com> wrote in
news:WE******************@bignews6.bellsouth.net:
sql_error_err:
MsgBox Err.Number
MsgBox Err.Description
Debug.Print Err.Description
Debug.Print Err.Description
Debug.Print Err.Source
Resume sql_error_exit


Why not:

MsgBox Err.Number & ": " & Err.Description

That's the way I always do it.

Then you can handle the error like this:

Select Case Err.Number
Case 123 <-this would be the error you want to handle
Resume Next <-this would ignore the error
Case Else
MsgBox Err.Number & ": " & Err.Description
Resume sql_error_exit
End Select

I can't see why you'd have a problem, except for the fact that
you're splitting up the notification of errors into multiple parts.
So far as I know, if an insert fails, it just fails, with a single
error number, not with different errors for the different kinds of
reasons it can fail. But I haven't checked.

Reading between the lines it seems you want to discard the
duplicates. I would never do it that way, as it always seems
dangerous, and it bothers me esthetically to knowingly cause an
error. Instead, I'd write my INSERT SQL with an outer join to the
destination table so that any duplicates would be eliminated from
the append operation.

That way, any other errors that might happen in the insert operation
will be for some other reason, a reason that you might want to
handle for its own sake.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: no one | last post by:
I have been searching various boards trying to figure out how to generate an image along with other html. I intend to put the image in a table, but for now I am just having problem getting the...
8
by: frank | last post by:
Below is some code for doing and insert into one of my tables. The inserts do not work because a duplicate key exists, which I want to happen. The problem is, I cannot get access to return an error...
1
by: GSteven | last post by:
I have a statemnt which says: CurrentDb.Execute strSQL, dbFailOnError where strSQL is a create query. Is there an overwrite option for the execute method so thath I don't get the 'file already...
2
by: Max Power | last post by:
Hi All I am coding a small app in that swaps specific files between a client and server. All files and locations are set at both sides. I want my app to show a file list, based on the file...
2
by: jane007 | last post by:
Hi everybody, Anybody who know how to use Net::Telnet module to execute my own script?Not only to execute system command. Please advise. Thanks.
1
by: mountainbig | last post by:
Greetings! I have a table for for sales order with module information related to sales. i have a Module table with a list of modules. i am trying to create a query to pull all the sales...
1
MitchR
by: MitchR | last post by:
Hello Folks; I have run myself into a hole I cannot get of and need some assistance. I have a Form "Frm_ATandT_Activation_Center" that has a sub form "Frm_ATandT_Activation"....
13
by: matt753 | last post by:
Can anyone tell me whats wrong with this SQL statement? CurrentDb.Execute("INSERT INTO Joblist2Data (ID, DayUsed, Employee, Priority, Item, Task, Comments, Complete) VALUES (" & Null & ", #" & 5 /...
2
by: Higgs | last post by:
Hello, I have a function "ParseFileName" which removes the ".txt" in the file name which is stored in the variable varItem: Public Function ParseFileName(varItem As String) As String x =...
4
TheSmileyCoder
by: TheSmileyCoder | last post by:
I have been playing around with transactions and one thing got me wondering. First is the code I am using: 'Start transaction 'Get default Workspace. Dim wrkDefault As...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
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,...
0
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
Oralloy
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,...
0
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
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...

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.