473,465 Members | 1,651 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Catching SQL Errors

How do I catch SQL errors in Visual Basic in Access? I would like to
display a message box if the sql errors out instead of it popping up
with the Debug/cancel box.
Sep 26 '08 #1
4 14468
On Sep 25, 8:03*pm, iwasinnihon <iwasinni...@gmail.comwrote:
How do I catch SQL errors in Visual Basic in Access? *I would like to
display a message box if the sql errors out instead of it popping up
with the Debug/cancel box.
use 'on error...'

on error goto fErr
strsql = "select * from tblCity..."
set rs = currentdb.openrecordset(strsql)
...
...
fExit:
set rs = nothing
exit sub

fErr:
debug.print err.description ' this will print the error message to you
can
' log to a text file
resume fExit
Sep 26 '08 #2
I tried what you said, but it runs the error everytime now. See code
below.

Private Sub Add_Note_Button_Click()
If IsNull(Me.Add_Note) Then

Else
Dim sql As String
sql = "INSERT INTO LPC_Notes VALUES('" & Me.Index_Number & "','" &
Me.Add_Note & "','" & Me.NoteDate & "');"
On Error GoTo AddError
CurrentDb.Execute sql, dbFailOnError
Me.Add_Note = Null
Me.Notes.Requery
End If
Me.Add_Note.SetFocus

Exit_Function:
Exit Sub

AddError:
MsgBox ("Invalid entry. Make sure you are not using any special
characters and resubmit.")

Resume Exit_Function
End Sub
Sep 29 '08 #3
iwasinnihon wrote:
I tried what you said, but it runs the error everytime now. See code
below.

Private Sub Add_Note_Button_Click()
If IsNull(Me.Add_Note) Then

Else
Dim sql As String
sql = "INSERT INTO LPC_Notes VALUES('" & Me.Index_Number & "','" &
Me.Add_Note & "','" & Me.NoteDate & "');"
On Error GoTo AddError
CurrentDb.Execute sql, dbFailOnError
Me.Add_Note = Null
Me.Notes.Requery
End If
Me.Add_Note.SetFocus

Exit_Function:
Exit Sub

AddError:
MsgBox ("Invalid entry. Make sure you are not using any special
characters and resubmit.")

Resume Exit_Function
End Sub
Do a
debug.print strSQL
You say it will error out. If not, comment out the On Error Goto line.
Now Go to the Debug/Immediate window and enter
? SQL
Who knows, change the name to strSQL. See reserved words at Allen
Browne's site
http://allenbrowne.com/AppIssueBadWord.html

Sep 29 '08 #4
On Sep 25, 10:03*pm, iwasinnihon <iwasinni...@gmail.comwrote:
How do I catch SQL errors in Visual Basic in Access? *I would like to
display a message box if the sql errors out instead of it popping up
with the Debug/cancel box.
Are these errors that occur in a stored procedure in some other
database (like Oracle) that you call from VBA via ADO? If so, there
are protocols for handling them.
Oct 1 '08 #5

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

Similar topics

1
by: Florian Fredegar Haftmann | last post by:
Hi! I'm working on a tool which helps in testing applications with web-frontends (on Windows) On thing I would like to test ist the occurence of JavaScript errors; the idea is that the test...
2
by: PapaBear | last post by:
Hi y'all, I'm handling Apache errors through seperate shtml files. That surely looks better than the standard error pages by the browser etc. I did this by coding in httpd.conf lines like: ...
2
by: fred | last post by:
Hello, I read a file from several classes and want to catch an EOF when it appears. Having caught the EOF I want to allow the final part of the program to continue rather than just exiting. ...
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
0
by: R. MacDonald | last post by:
Hi, I have a VB.Net application that dynamically calls unmanaged routines in a DLL that has been created by Fortran (DVF v5). The call to the DLL routine is within a Try/Catch block, but when...
2
by: Eric Lilja | last post by:
Hello, consider this complete program: #include <iostream> #include <string> using std::cout; using std::endl; using std::string; class Hanna {
1
by: Hari Sekhon | last post by:
I've written an except hook into a script as shown below which works well for the most part and catches exceptions. import sys def myexcepthook(type,value,tb): do something ...
4
by: John Pye | last post by:
Hi all I have some C code that is giving me some 'nan' values in some calculations. The C code is wrapped using SWIG to give me a Python module that I am then exercising through a unittest...
25
by: JJ | last post by:
I only want to catch 404 errors at the application level (the rest are will be handled by the customerrors section of the web.config). How do I check for the error code in the Application_Error...
3
by: john | last post by:
I wrapped some fortran code using F2PY and need to be able to catch fortran runtime errors to run the following: # "grid" is a wrapped fortran module # no runtime errors incurred when run with...
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
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
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...
0
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,...
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.