|
-
May 11th, 2007, 09:35 PM
#1
Thread Starter
Member
[RESOLVED] "No error" condition
I want to enter data into a database, and if I get no errors, I want to put an error box saying the data was added. I don't want to get into a convoluted error handling scheme. Is the abscense of a return code a feasible way of handling this? Any suggestions? Alternatives?
-
May 11th, 2007, 09:59 PM
#2
PowerPoster
Re: "No error" condition
i think you cannot really avoid complex code especially when you really want to have a full proof code.
-
May 12th, 2007, 12:08 AM
#3
Re: "No error" condition
Not sure I understand your question...
Why not just use a simple error handler?
vb Code:
On Error Goto DamnErrors
'Database code here...
Exit Sub
DamnErrors:
Select Case Err.Number
Case 1234, 308, 302, 999
Debug.Print "Known error..."
Case Else
Debug.Print "Unknown error"
GiveUp()
GrabBeer()
WatchTV()
End Select
-
May 12th, 2007, 08:11 AM
#4
Thread Starter
Member
Re: "No error" condition
I can use digirev's suggestion, but I don't really care what the error is. Do I have to list all the errors in order to do a Select? Is there a printable list of all VB error codes someplace?
-
May 12th, 2007, 08:36 AM
#5
Re: "No error" condition
why do you need to worry about errors anyway? All you need is a basic On Error Handler without the select case, and just check if there were no errors so you can post the message box.
-
May 12th, 2007, 09:10 AM
#6
Re: "No error" condition
How quickly this got away....
simple error handling at it's minimalist:
Code:
On Error Goto errHandler_DB
' ... do your database stuff
'If it gets here, there's no error
MsgBox "Added!"
resume_Sub:
Exit Sub/Function/Property/Whatever
errHandler_DB:
MsgBox "Error #" & cstr(err.Number) & " - " & err.Description
Resume resume_Sub
End sub/function/property/whaterver
A "no error" condition is called "normal operation"... meaning nothing goes wrong. IT should follow the normal course of the flow. The only time it should deviate is where there is an error.
DigiREv came the closest, but complicated by useing the select case... which you only really need to do if you want a specific message for specific errors, or want to do something different based on the errors. But it sounds like in your case, just simply knowing if there was an error (which goes to the error handler) or not (stays within the normal program flow) is enough.
-tg
-
May 12th, 2007, 09:56 AM
#7
Thread Starter
Member
Re: "No error" condition
Works like a charm, but I'm not sure if I'm causing a potential problem in closing the connection. Here is the portion of code that is of concern. Do I have a potential problem in exiting the sub before I close the connection?
Code:
...
strSQL_Insert = "INSERT INTO tblSizes (Dimensions, CupDepth, CupVol, DieArea, CupArea, HobNumber, Shape )"
strSQL_Insert = strSQL_Insert & " VALUES ('" & strAddToolDimension & "', " & sngAddCupDepth & _
", " & sngAddCupVolume & ", " & sngAddDieArea & ", " & sngAddCupSurfaceArea & _
", '" & strAddHobNumber & "','" & strAddShape & "')"
MsgBox "Added!"
resume_Sub:
Exit Sub
errHandler_DB:
MsgBox "Error #" & CStr(Err.Number) & " - " & Err.Description
Resume resume_Sub
cn.Execute strSQL_Insert
cn.Close
Set cn = Nothing
End Sub
-
May 13th, 2007, 08:54 PM
#8
Re: [RESOLVED] "No error" condition
Why are you executing the SQL in the Errorhandler? Especially when it will NEVER execute.
You're building the SQL, displaying a message box and exiting the sub. There's nothing there to error out, so it will never get to the Erorr Handler. And even if it did, your Resume will jump straight to the exit sub, and NEVER call the cn.Execute, and never will the cn.Close.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|