473,765 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help desperately, Problem Generating Errors for currentdb.execu te

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 2525
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.co m> 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_er r:
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.co m> 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.Execut e sql, dbFailOnError

sql_error_exi t:
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.co m> 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.co m> 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.Execu te sql, dbFailOnError

sql_error_ex it:
Exit Sub

sql_error_er r:
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.co m> 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.co m> 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.Execut e sql, dbFailOnError

sql_error_e xit:
Exit Sub

sql_error_e rr:
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.co m> 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.co m> 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.co m> 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
>conditio n.
>
>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.Execu te 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.co m> wrote in
news:WE******** **********@bign ews6.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
2010
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 image to generate alongside other html. I am using a form to set variables such as colors, text, font, etc and that works fine as long as I set the header to image/jpeg. The problem is I need the resulting page to show more than just the image....
8
477
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 for this condition. What can I do to get access to return an error on my query? Thanks
1
17116
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 exists' error? tia Steve
2
9096
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 names, from the local and remote machine..... Local is not a problem and works OK. but I am trying :: Form1.getFile.FileName = Inet1.Execute("ftp://ftp.server.net", "DIR") and I
2
5742
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
994
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 accounts with modules that do not exist in the modules table. and i need the following columns pulled in the results AccountID AccountName SalesOrderID SalesLineID PartNumber PartNumberDescription Module
1
3113
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". Frm_ATandT_Activation_Center is standard in Form View with no Master or Child links to the Sub form. this allows me to show available SIM ID"S in inventory for activation. The Subform diplays as a datasheet that has a Query as the control source. So when the user opens...
13
6067
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 / 27 / 10 & "#, " & cmbTechnician.Value & ", " & Null & ", " & Null & ", " & txtOrderID.Value & ", " & comments & ", " & False & ");") I have the Err.Description going out to a messagebox and it says "Error in INSERT INTO statement" The first...
2
8682
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 = InStrRev(varItem, "\") sFile = Mid(varItem, x + 1) sFile = Left(sFile, Len(sFile) - 4)
4
9964
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 Workspace Set wrkDefault = DBEngine.Workspaces(0) 'Start of transaction wrkDefault.BeginTrans Dim strSQL As String
0
9398
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
10160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9951
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
8831
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
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
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
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
2
3531
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.