Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Error Trapping And Data Validation


I need help in making writing error handling or data validation for this code I'm kind of stuck..it's been a long dreary day and my brain is maxing out..

'** Run report with specified parameters
strReportPath = Trim(rsReports("ReportPath"))
Set objReports = CreateObject(strReportClass)
strPDFReport = objReports.RunReport(strReportPath, colParameters)

'****I would like to add a data validation here or *******handle an error if report doesn't run correctly.


'get user information
sSql = "select * from securityuser where userid = " & lngUserID
stat = oDB.FillRecordSet(rsUser, sSql)

If stat = 0 And (bSendEmail = True) Then

strUserNameMany(0) = rsUser("FirstName")
strUserEmailMany(0) = rsUser("email")
lngUserIDMany(0) = lngUserID
'send email to person
If (rsUser("email") <> "") Then
stat = EmailResults(strUserEmailMany(), strFreqType, strUserNameMany(), rsReportID("ReportName"), strPDFReport, lngUserIDMany(), True)
strUserPDF = strPDFReport
If strFreqType = "Now" Then




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Automation Error When Populating Data Validation Dropdown
I've seen a number of threads dealing with the mysterious "Object invoked has disconnected from its clients" error and I have a slightly different twist on this issue. I'm running into this error trying to populate a data validation dropdown list programmatically using VBA.

I have about 25 worksheets in an Excel workbook that correspond to Oracle database tables. In these worksheets, we have columns representing code fields here and there and want the user to only be able to enter in a valid code.

To accomplish this, I wrote a subroutine that gets the valid codes and their descriptions from the proper Oracle table, adds each code to a comma delimited string and then adds data validation dropdowns to the cells in that column containing the available codes and their descriptions.

The same subroutine is called in every instance and it works great for the majority of the code fields. However, there are certain fields that give me that "Object invoked has disconnected from its client" error when I try to populate the dropdowns in their column.

Here's the subroutine code. This subroutine is called numerous times using the same ADODB Connection object from the Workbook_Open routine. I'm a newbie at VB, so I apologize if my code could be better. This site has actually been a huge help to me so far.


Code:
Private Sub ApplyDataValidation (ByVal codeName as String, ByVal worksheetName _
as String, ByVal column as String, ByVal conn as Connection)

Dim numItems as String
Dim itemList as String
Dim recSet as ADODB.Recordset

numItems = 0
itemList = ""

Set recSet = conn.Execute ("SELECT " & codeName & "_CODE, " & codeName & "_DESC FROM " & codeName & "_VV")

Do Until recSet.EOF
If numItems > 0 Then
itemList = itemList + ", "
End If

itemList = itemList + recSet(codeName & "_DESC") & " - " & recSet(codeName & "_CODE")
Loop

If numItems > 0 Then
With Worksheets(worksheetName).Range(column & "3:" & column & "40").Validation
.Delete
.Add Type:=xlValidateList, Formula1:=itemList
End With
End If

End Sub


As I said, 90% of the code dropdown lists are populated without issue. It's the remaining 10% that are a problem. Is there a limitation on how long the dropdown list can be or a way to only show 10 items and have a scroll bar on the validation dropdown? One of the code fields has 269 valid codes.

Any help would be greatly appreciated.

CommonDialog RunTime Error Even WITH Error Trapping
Right, heres the code

Code:
Private Sub cmdAddFiles_Click()

'DIM LINES
'*
'*
'*
'*

On Error GoTo ErrHandler

'cdl is CommonDialog Control

cdl.InitDir = "\" & txtLocation.Text & txtRemotePath
cdl.flags = cdlOFNAllowMultiselect + cdlOFNExplorer + cdlOFNLongNames
cdl.CancelError = True

cdl.ShowOpen

'/
'/
'/
'/
'OtherCode
'/
'/
'/
'
Exit Sub



ErrHandler:
    If Err.Number = 32755 Then

    'CODE************
        
    End If

    Exit Sub

End Sub



Basically, even with the error trapping, the IDE is still throwing back a 32755 runtime error saying "User pressed Cancel" or something like that. I need code to happen if cancel is pressed. Is there something I'm doing wrong?

Thanks in advance

Xeno



Edited by - Xenobyte0 on 1/14/2005 5:08:43 PM

Help With Error Trapping
Hello everyone. I've come up with this code to delete the workbooks Open event from all the workbooks listed in column A. The problem is if one of the workbooks doesn't have a workbook open event, I get an error 35...saying it doesn't exist. Fair enough, however, I can't seem to figure out where to put the "on error" part of my code. Here is what I have:


Code:
Sub removeSpecificCode()
'this code will remove the workbooks "Open" event from all the workbooks
'listed in column A.
Dim awcl As Integer
Dim i As Variant
Dim myBk As String
Dim myDir As String
Dim myRng As String
Dim VBCodeMod As CodeModule
Dim StartLine As Long
Dim HowManyLines As Long

myRng = Worksheets("Sheet1").Range("B1").Value
myDir = Worksheets("Sheet1").Range("C1").Value

For Each i In Worksheets("Sheet1").Range(myRng)

myBk = i.Value

Application.ScreenUpdating = False
Application.EnableEvents = False

Workbooks.Open myDir & myBk ', , , , "password", "password"

Set VBCodeMod = ActiveWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule

On Error GoTo HandleErr

With VBCodeMod
StartLine = .ProcStartLine("Workbook_Open", vbext_pk_Proc)
HowManyLines = .ProcCountLines("Workbook_Open", vbext_pk_Proc)
.DeleteLines StartLine, HowManyLines
End With

HandleErr:

Application.DisplayAlerts = False
Workbooks(myBk).Close

Next

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub
It works fine on the first workbook it encounters if it doesn't have a workbook open event, but if there is a second workbook, it stops and gives the same error...can anyone tell me where to put the on error part of my code or perhaps show me a better way of doing this?

Thanks,

Dave

Trapping An Error
I'm having a problem trapping run time error 457, a duplicate key to a collection. I want, if the item in the collection already exists, to just reference the particular object in the collection (not add a new object) and pass it the value of a wav file. But it won't. Here's the code for the procedure:

Public Sub PlayThisSound(ByVal ASoundFile As String)
Dim TheNameOfTheWAV As String
Dim APlayer As New WAVPlayerClass
Dim rv As Long

If Players.Count = 0 Then
'KillCode = SetTimer(0, 0, 250, AddressOf CheckWAVPlayersStatus) 'Creates a timer and gets its' identifier...
End If

TheNameOfTheWAV = ASoundFile
On Error GoTo SoundIsAlreadyPlaying:

Players.Add APlayer, Key:=TheNameOfTheWAV 'Adds an instance of a WAVPlayerClass to the Players collection with TheNameOfTheWAV as the key...
Players(TheNameOfTheWAV).PlayThisWAVUtility TheNameOfTheWAV 'Begins to play the sound from the beginning...

GoTo NoErrors:
SoundIsAlreadyPlaying: 'If a WAVPlayer object already exists for this sound, it is told to start over...
Players(TheNameOfTheWAV).PlayThisWAVUtility TheNameOfTheWAV
Err.Clear

NoErrors:
Set APlayer = Nothing

End Sub

Any suggestions? I have the timer rem'd out for now because while I'm working on it, it can leave it active and I have to exit VB to turn it off, but it works if nothing bombs. Thanks.

New To Error Trapping.
Trying to connect between 2 winsock controls and the connectionrequest event isn't even firing. Here is some error trapping I did, don't know if this will help but when I trap the sckError this is the results of my query.....

[Client]
wsC.State= 9 - sckError
wsC.RemoteHost= 192.168.1.102
wsC.RemotePort= 3030 - assigned
wsC.LocalPort= 2693 - random

[Server]
wsS(FirstFreeSocket).State= 2 - listening
wsS(FirstFreeSocket).RemoteHost=
wsS(FirstFreeSocket).RemotePort= 0
wsS(FirstFreeSocket).LocalPort= 3030 -assigned

Trapping An Error
Hello,

I want to be able to trap an error should my file not be found.
The examples in the books I've referred to use inputboxes to get the user to enter the file they wish to open however, I want to open the file on form load without the user having to open it. My code is basic:

open "c:docsexample.txt"

I would like to be able to display a message should the file not be found I've tried:

error = open "c:docsexample.txt"

but as i'm sure you gurus are more than aware this does not work!

Any ideas at how I can use error handling to overcome this problem.

TKS

Ben

Error Trapping
i am having difficulty trapping an error that occurs if the app is closed prematurely by the user (using the X button).

code is:

sub unloadallforms()
on error resume next
kill (file)
kill (file)
' unload forms and set to nothing routine here
end sub

also tried:

sub unloadallforms()

on error goto errhandler

kill (file)
kill (file)
' unload forms and set to nothing routine here

exit sub

errhandler:
resume next
end sub



it is the kill command that causes the error (not if the app finishes as normal only when closed by the user)

hope you can help

Error Trapping-again
Tried to get an answer before- but still can't figure it out. Here is what I want to do:

First off: have 2 sub directorys named ptext and ppic
the ptext contains text files such as plant.txt
the ppic contains images such as plant.bmp
now when the program comes to this line of code:
-------------------------------------------------------------
Image1 = LoadPicture(App.Path & "pdatappic" & File1.Filename
& ".bmp")

what I want to do is if say plant.bmp is not on file, I would jump to a sub containing this code:

Image1 = LoadPicture(App.Path & "Pdatappiclankpic.bmp")

please explain how to do this, its been driving me crazy.

Error Trapping
I haven't understood Visual Basic error trapping yet. I want to use it like a try and catch statement in C++ or Java in a for loop - I try to do something in the loop and if it fails I clean up and continue with the next lap.

This is my code:

For i = 0 To 10
OnError GoTo OnError
' Do nasty stuff that might fail.

OnError:
' Clean up.
Next i

This code traps ONE error, but if there is a second error in the loop for another index "i" I'll get a runtime crash. What's wrong?

And another question - do I have to turn off error trapping after the loop with "OnError GoTo 0"?

Error Trapping
hi all, can someone please tell me how i can change the text of a text box if the text is "" cause im making a kind of calculator and when "" is in a text box the prog crashes....basically i just need it to become 0 so the calculator has a number to deal with and not a null so to speak.....all help counts...thanks

Error Trapping
Suppose you have a large sub with multiple objects being used. When you use error handling, how can you tell what object generated the error? If, for example, a file system object raises error number 5 for a disconnected network drive but your winsock object also raises error number 5 if a hamster has clogged your port...how do you know which object raised error #5?

Ty

SQL Error Trapping?
I am having trouble when i query a SQL database for a record that isn't there; it returns an error message and pauses my program until i press "ok". When i request a record that isnt there i need it to skip that request and move on to the next one. here are the lines of code that I am using:

sqlPPID = "SELECT PatientProfile.PatientProfileId FROM PatientProfile Where PatientProfile.PatientId = "

Adodc2.RecordSource = sqlPPID & ChartNum

Adodc2.Refresh

ChartNum is a string that represents the record i need to select from the database. Is there a way using SQL or VB to determine if that record exists before i try to retrieve it?

Help With Error Trapping
Hello,
I'm currently querying an SQL database with the following commands:

oConn.Open sConnection
oRs.Open sSQL, oConn

getntusername = oRs("ntaccount")

oRs.Close
oConn.Close
Set oRs = Nothing
Set oConn = Nothing


There is a bunch before and after but this is the gist of it, basically it all works fine if the record exists, but if it finds a record missing it errors out. How can I error trap for this, basically I'm passing a full name at the database and it is returning an NT username, this query is how I'm confirming for valid NT username so if the username doesn't exist I just want to write it to a log. I can handle the log writing part, however I need to be able to trap it if it fails rather than an error. On error resume next results in the program hanging so that isn't an option... Any ideas?
Tom

Error Trapping
Hello there!
this forum ha helped me before and I have a question that is not that difficult but still puzzels me.


Below is a code to insert data into a access db 2000 through VB.6. All is well, but when I try to trap the error if there are duplicates it seems as if the error number changes!? now I have it to the number below but it is hard to trap en error when it is based on a number that may not be the right one other times, surely this can not be true?

Code:
Private Sub cmdSave_Click()
txtDi.Text = LCase(txtDi.Text)
txtUser.Text = LCase(txtUser.Text)
txtFirstname.Text = LCase(txtFirstname.Text)
txtLast.Text = LCase(txtLast.Text)
Dim ShouldContinue As Boolean

On Error GoTo SameInfo

ShouldContinue = True
' If ShouldContinue Then ShouldContinue = (txtDi.Text <> vbNullString) ' one wants to check the Di later
If ShouldContinue Then ShouldContinue = (txtUser.Text <> vbNullString)
If ShouldContinue Then ShouldContinue = (txtFirstname.Text <> vbNullString)
If ShouldContinue Then ShouldContinue = (txtLast.Text <> vbNullString)
If ShouldContinue Then ShouldContinue = (cmbBuilding.Text <> vbNullString)
If ShouldContinue Then ShouldContinue = (txtFloor.Text <> vbNullString)
If ShouldContinue Then ShouldContinue = (txtOfficeNb.Text <> vbNullString)
If ShouldContinue Then ShouldContinue = (txtOfficetelNb.Text <> vbNullString)

If ShouldContinue Then
Rs1.AddNew
If txtDi.Text = "" Then
Rs1.Fields("ComputerID") = "N/A"
Else
Rs1.Fields("ComputerID") = txtDi.Text
End If
Rs1.Fields("Username") = txtUser.Text
Rs1.Fields("Firstname") = txtFirstname.Text
Rs1.Fields("Surname") = txtLast.Text
Rs1.Fields("Building") = cmbBuilding.Text
Rs1.Fields("Floor") = txtFloor.Text
Rs1.Fields("Office") = txtOfficeNb.Text
Rs1.Fields("TelephoneOffice") = txtOfficetelNb.Text
Rs1.Update
MsgBox "Record Saved", vbInformation, "Record is Saved"
Installation.cmbUser.AddItem (txtUser.Text)
txtUser.Text = ""
txtFirstname.Text = ""
txtLast.Text = ""
txtDi.Text = ""
txtFloor.Text = ""
txtOfficeNb.Text = ""
txtOfficetelNb.Text = ""
Else
MsgBox "You have not entered all required * fields "
End If


SameInfo:
If Err.Number = -2147467259 Then
MsgBox "Username already exists"
Err.Clear
ShouldContinue = False
End If

End Sub

SQL Error Trapping
Hello all.

I have a program that connects to a SQL database and performs a select query based on user input.

I am looking to add some error trapping so that if the network is down at a site and the program cannot connect to the SQL server then I will be able to gradually handle this with a message box and a update a label on my form.

Right now all it does is give a cryptic sql message about no database connection found or timeout error.

Two, is that I am adding a component to insert five values into a SQL table, and I want to trap the error if it cannot create the record. Maybe try again and then bypass it.

Any ideas would be great.

Thanks
Garry B

Error Trapping
i need help. i have a program and sometimes it fails when it does the whole program crashes. how can i make it where the whole thing doesn't crash?

Trapping Error
I use combo box, I would like to do trapping error.

When there is no list of file in combo box. I got an error message " Invalid properties value". How to do so that I not get the the error like this?


Code:

Combo3.ListIndex = 0
Combo3.Text = Combo3.List(Combo3.ListIndex)

Error Trapping In VBA
Hi,
I have a problem in VBA. The error handler does not show me what errors occur and where the code breaks but rather ends the complete code.

e.g.
in line

Variable1 = Variable0 / 0

i want the error handler to stop there and tell me 'divison by zero' rather then stop the complete function. This must be a setting somewhere in VBA but I cannot find it. Please help.

Trapping Error 53 Help
I am trying to trap an error 53 (File Not Found). Basically the code attempts to load a file inputed into a text box. If the user types an incorrect file name the error 53 occurs. I tried using this:

VB Code:
Private Sub Command3_Click() On Error GoTo Cmd3Err         Err.Raise 53         Exit Sub Cmd3Err:      Select Case Err.Number         Case 53            MsgBox "File Not Found."      End Select <There is additonal code here.>

No matter if there's an error or not the MsgBox appears. Help?

Error Trapping
Trying to prevent duplicates from being entered into database.... How do I have the app search the db for a username AND date match, so I can yell at the user through an error message? LOL

Thanks in advance.......

Error Trapping
Does anybody know how to trap errors that could happen in all the object event procedures (textboxes, pictureboxes, listboxes, etc, etc) in a VB program? Obviously, I don't want to put On Error Goto lines in every single event procedure as I have got thousands of such procedures!

Kind Regards, markunosquirrel

Error Trapping
Heya,
Im just learning how to use drive list boxes and i've run into a problem. Whenever a device is sleceted that isn't availble my program will crash. How do i go about trapping this run-time error?

Need Help With Trapping Error
Here is the code. It works just fine unless ActiveDate1 or txtTimeClosed = "" then I get Runtime error "13"

I've tried several ways to try and trap the error which is the result of the user not putting in a Date in ActiveDate1 or leaving the txtTimeClosed empty. ActiveDate1 is a dropdown calendar and the user clicks a button to insert the time closed. Any help would be greatly appreciated.

VB Code:
Private Sub Command1_Click()    Dim First, Second, Third, Fourth   First = Val(txtFee.Text)   Second = Val(txtPhoto.Text)   Third = Val(txtMileage.Text)   Fourth = Val(txtOffice.Text)   txtBaseFeeTotal = First + Second + Third + Fourth  Dim Five, Six, Seven, Eight   Five = Val(txtBaseFeeTotal.Text)   Six = Val(txtAdPhoto.Text)   Seven = Val(txtAdMileage.Text)   Eight = Val(txtAdOffice.Text)    txtSubTotal = Five + Six + Seven + Eight  Dim Nine, Ten   Nine = Val(txtSubTotal.Text)   Ten = Val(Text19.Text)   txtTaxTotal = Nine * Ten / 100 Dim Eleven  Eleven = Val(txtTaxTotal.Text)   txtTotal = Nine + Eleven   If Text1.Text = ActiveDate1.Text Then   txtTATdays = 0   Text10.Text = DateDiff("h", frmAdminInfo.txtTimeRecd.Text, txtTimeClosed.Text)Else   txtTATdays.Text = DateDiff("d", Text1.Text, ActiveDate1.Text)  Text10.Text = DateDiff("h", Text1.Text, ActiveDate1.Text)End IfEnd Sub

Thanks for any and all help

Error Trapping
I need help in this please. I need to trap an error if no file is on the hard drive. Here is the code I'm using, but it isn't working:
On Error GoTo x



Items = 0
place = 1
Open App.Path & "cocoa.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, item
Items = Items + 1
Label2.Caption = Items
lenghtofline = Len(item)
control = 0
For i% = 1 To lenghtofline
letter = Mid(item, i%, 1)
If letter = Chr$(124) Then
control = control + 1
letter = ""
If control = 1 Then
picturenumber(place) = hold
hold = ""
End If
If control = 2 Then
picturetitle(place) = hold
hold = ""
End If
If control = 3 Then
itemdescription(place) = hold
hold = ""
End If
If control = 4 Then
catalog(place) = hold
hold = ""
End If
If control = 5 Then
price(place) = hold
hold = ""
End If
If control = 6 Then
unitofissue(place) = hold
hold = ""
End If
If control = 7 Then
pictureofitem(place) = hold
hold = ""
End If

End If
hold = hold + letter
letter = ""
Next i%
hold = ""
place = place + 1
Loop
Close #1
locationoffile = App.Path & "pictures0001.gif"
Picture1.Picture = LoadPicture(locationoffile)
control = 0
cmdbackwardsbtn.Enabled = False
For i% = 1 To 24
control = control + 1
locationoffile = App.Path & "pictures"
filepicture = pictureofitem(control)
together = locationoffile + "" + filepicture
imageplacement(i%) = together
Image1(i%).Picture = LoadPicture(together)
Next i%
x:
If Err = 53 Then MsgBox "Sorry Your Last Order is not on disk"
End Sub

please email me at jamaica125@msn.com
Dan Regalia

Error Trapping
hey - i have it so when the person runs my program for the first time i extract a blank database (with the neccessary columns and whatnot). up to now, everything works great. the only problem is that when the user runs i get an error 3021: "No current record." how can i trap this error before i get it and add in an extra record so it'll work?

ps i don't want to add the record if the db isn't empty

Error Trapping
I have an error handler that will auto notify the development team if an error occurs that has not been planned for. But it skips the error handler for 0.

Can anyone help me out?

Here is the code:

on error goto errhandler

errhandler:

Select Case Err.Number
Case 0

Case 7009
~~do this code~~
Case Else
Call Notification
End Select

Trapping ASP Error??
How do I trap this error on an asp page???


Microsoft JET Database Engine error '80004005'

Could not use ''; file already in use.


I have an asp page that connects to access database. When the database is update (replaced with another copy), this occurs every 30 minutes. This error is generated.

How do I trap this???

/Smirre

Trapping An Error
I have an open common dialog and I want to trap when the user hits cancel. I have read the archives and I have one question.
The code such as
On Error Goto Errline

If Err.Number
etc
Do I put this code into the command click sub or do I create a new error sub?
Thanks

Error-trapping Help
hi all,
could anyone advise me as to the best way to add a error-trapping procedure to a program im writing. (new to vb)
i want it to show a message if a user tries to open a file that no longer exists in either the open procedure of a common dialog or a recent file menu option, at the moment i get
run time error 53, file not found .
thanks tink.

Better Error Trapping
Rather than...

VB Code:
On Error Goto Stuff' code that [i]might[/i] cause errorsExit Sub Stuff:' error handling  


Can I do something like...

VB Code:
On Error Goto Stuff' code that [i]might[/i] cause errors If Err = 0 Then ' no error, keep on gong    ' more codeEnd If Stuff:' error handling  
?

Need Help Trapping An Error!
Hey, I need some help trapping an error. I need a way to handle this error: If it tries to go to the next item in the listview and there is not a next item, then I get the "out of bounds" error. So how can I make it just cancel if there is not a next item in the listview? Someone tried to help earlier, but It just confused me even more. Any help appreciated.



PHP Code:




If Now() > origTime + songTime Then 'check for end of song
        Timer2.Enabled = False
        counter = ""
        Songtitle = ""
        Frequency = ""
        bitrate = ""
        ListView2.ListItems(MusicMaster.ListView2.SelectedItem.Index + 1).Selected = True
End If

SQL Error Trapping?
Is there a way to trap a SQL Server returned error? I have an app that keeps bombing out and I get a MSDTC is unavailable and it kills the app with a Run-Time error. How do I trap it and keep the app from dying. I have Error handlers on every procedure, but the don't seem to work.

Error Trapping
Is there any way to write your error trapping code in a module, and get this module called whenever an error is fired. I mean, instead of the classic "On Error Goto Label", could it be re-address to a subroutine or Label in a bas module?

Error Trapping
Error Trapping


I am reading a "DBF" that contains 15000+ lines. After the application finishes, I parse two files (header file and body) into one file using FileSystemObject and TextStream.
About half way through reading the file and performing my calculations, I get a run-time error of
-2147220452. What the heck is this error?
I tried a for each loop to get a description and the results were "application defined error" or "object defined error." Can someone please tell me how to fix this problem?


Thanks

Trapping An Error
Hello,

I want to be able to trap an error should my file not be found.
The examples in the books I've referred to use inputboxes to get the user to enter the file they wish to open however, I want to open the file on form load without the user having to open it. My code is basic:

open "c:docsexample.txt"

I would like to be able to display a message should the file not be found I've tried:

error = open "c:docsexample.txt"

but as i'm sure you gurus are more than aware this does not work!

Any ideas at how I can use error handling to overcome this problem.

TKS

Ben

SQL DMO/ Error Trapping.
I am using SQL DMO in an app that I am currently developing and have come across a problem trapping an error. The error is coming from SQL not my app, things like invalid user name or password. Because the error is coming from SQL my usual error handling routine is not working. Could someone tell me how to trap this kind of error?

Thank You

Lyle A Krueger

Error Trapping
Hi guys
I'm getting an error with a number of 8004oe14. Can someone plese tell me how to write an error trap for this error number.
Thanks a lot
JK

Need Help Bad, Error Trapping
I'm writing a error trapping and logging routine for
a program I made a few weeks ago. It has some
quite long functions, so I made a error logging
routine. The program is called from the other functions
like as below,

sub test
on error goto error

end sub <-----------------------------------
error: |
call errorfunc |
end sub |
|
I even tried it by changing the first end sub | to end,
but my program stops executing every time somewhere.
I need the program to continue through the errors. but log them so I can go back and fix them for different customers
below is my error function if you're interested.



Public Function LogError(ByVal ErrDateTime As Date, ByVal procname As String, ByRef ErrObj As ErrObject, Optional FormObject As Object, Optional CommandString As String)
Dim intFileO As Integer
ErrDateTime = (Date)

On Error Resume Next

intFileO = IntFile(0)
MsgBox ("An error occured, and a Log file is being created")
Open App.Path & "Error.log" For Append As intFileO

If IsMissing(FormObject) And IsMissing(CommandString) Then
Write #intFileO, ErrDateTime, procname, ErrObj.Description,
ErrObj.Source
ElseIf Not IsMissing(FormObject) And Not IsMissing(CommandString) Then
Write #intFileO, ErrDateTime, procname, ErrObj.Description,
ErrObj.Source , FormObject.Caption, CommandString
' a routine to dump all values found in a form
Call DumpFormValues(intFileO, frmRecordCard)
ElseIf Not IsMissing(CommandString) Then
Write #intFileO, ErrDateTime, procname, ErrObj.Description,
ErrObj.Source , CommandString
End If

Close intFileO
On Error GoTo 0
Err.Clear
On Error GoTo errhndlr
End Function
errhndlr: Call LogError(ErrDateTime, procname, ErrObj, FormObject, CommandString)
End Function

Error Trapping ?
Hey,
can someone give me the simplest example of error trapping?
if there is no simple example, no prob.
thanks

Error Trapping From VB6
I'm using VB6 against an SQL Server database.
Can anyone tell me-
If I use this statement from VB to do updates instead of calling a stored procedure:
Cn.Execute "update bill set agenda = '" & txtNewAgenda & _
            "', agendadate = '" & txtNewAgendaDate & "', addendum = '" & txtNewAddendum & "' " _
            & "where LBDCAgendaNum= '" & txtLBDCAgendaNum & "'"

I'm testing for errors in vb on the client-side but I can't ROLLBACK this transaction from VB, can I?

Thanks in advance.
John   

Error Trapping
I have a method that is to take in a integer value. If i pass in a string ot double, it will give an error "byref argument: type mismatch" during compilation. HOw do you trap this error and modify its description to your own? And how i know if a string or double, instead of the rightful integer has been passed into the method?

Athena

Error Trapping
When my error handling catches an error in a routine is there a way to show what routine it was from?

See this example for a better understanding of what i'm asking:


Private Sub AddClient()

   On Error goto ERR_HANDLER

   'all code here; assume when this code is run an error will occur
    
exit sub
ERR_HANDLER:
   msgbox "This error was generated from routine " & ???????? & " in form/module " & ??????????????


End Sub


Any advice would be appreciated.. Thanks
Matt

Error Trapping In ADO Using VB6
New to VB, coming over from Delphi and need some help figuring out how to trap database errors in VB6 using ADO when manipulating data with Unique Record fields. Here is an example of my code:

Do until ado.Recordset.EOF

    ado.Recordset.Addnew
        ado.Recordset.Field("Number") = otherdatabase.Recordset.Field("Number")
        ado.Recordset.Field("Item") = otherdatabase.Recordset.Field("Item")
    ado.Recordset.Update
    ado.Recordset.MoveNext

Loop


The field "Number" is a unique field and should only be added once but since I have to re-check certain date ranges, it's possible to go over the same data multiple times.

When the code hits the section:
ado.Recordset.Field("Number") = otherdatabase.Recordset.Field("Number")
the program crashes with Error: Duplicate Entry. I'm wondering how I can bypass this error so the program will continue adding the unique records, but skip over records that it already has added.

Right now I'm just using an If statement to search the records to see if the number already exists, but this gets cumbersome when the table grows over a million records. Is there a simple way to simply skip these records but continue on with the MoveNext to keep adding ones that done exist? I've been trying out various forms of the OnError codes but cant seem to figure this out.

I'm coming over from Delphi so in Delphi it would look something like this:

Try
    ado.Recordset.Addnew
        ado.Recordset.Field("Number") = otherdatabase.Recordset.Field("Number")
        ado.Recordset.Field("Item") = otherdatabase.Recordset.Field("Item")
    ado.Recordset.Update
Except
    ado.Recordset.MoveNext
End

Which would Try to add a new record, but if it tried to add a Number that already existed in the Unique Number field it would simply skip that record and move on to the next.

Thanks!

Error Trapping
Hello all,

I have a flex grid bound to a recordset. One of the fields in the record set is numeric so if i enter anything but numeric value and try to go to another firld in teh grid an error generated because the record set does not take that value. I tried to trap teh error through the grid events i could not. Is there a way i can do that?

Please help, it is urgent!!

Error Trapping
When a VB 6.0 application generates an error;

1. How to write a single line error calling procedure in the startup form that will be executed on occurance on of therror anywhere in the application. The need is to avoid writing ON ERROR GO TO in every procedure.

2. Can Application tell which line of Code was running on occurence of an error. This was possible in old clipper / foxpro applications. These applications used to report the line number and as such identification of error used to be easier.

Regards,

Vishal Badle

Error Trapping
I know how the trapping work in global application (module and form).

I have 2 projects: The main project have forms and the other is a dll project.

My main using the 2nd project (dll). When my Main project calling a function in my dll project, if i get error, how i can send an error?
the err.raise put a msgbox and i would like that the error works like other error traping

ex: if u wanna try, make 2 project, a dll project and add a exe project (do that if u already did some project with dll)

In Main Project (normal.exe):

public function MyFunction
' add class from project dll
Dim mypan As clsPanorama

On Error GoTo test
Set mypan = New clsPanorama
mypan.DoErreur
Exit Sub
test:
MsgBox "That's work!"
end function

In DLL Project:

Public Function DoErreur()
Dim i As Long

On Error GoTo test
' making an error
i = i / 0
Exit Function
test:
' HOW TO SEND A ERROR THAT THE MAIN PROJECT CAN TRAP IT?
Err.Raise -1, "source", "description"
End Function

Only idea i have is to put a new parameter error:
function Test(Param1, Param2, byref Error as object) as variant

Better idea?
Regards
Alex

Error Trapping
Hi All
At present we are storing all errors coming in application in a Text file
I wanted to have some more sugestions on storing the errors like in a Table in database etc.

Regards
Nitya

Trapping The Same Error Twice
I am running into a unique situation in Visual Basic. I am trapping an error received from an Excel.Application object (1004). It occurs when the user enters a a file name that already exists, and when excel prompts them to overwrites, they choose 'No' or 'Cancel'. I trap the error, and send the user back to the file name entry point (GetSaveAsFileName method). If they repeat the process the a second time (enter a file name that already exists and then say No to overwrite) the error gets thrown again but VB ignores my handling code and gives its own error and quits the application. Could anyone tell me why the second time it ignores my On Error code? I've tried restating the On Error after an error is thrown, and I've tried calling err.clear, but neither worked. Any ideas? Thanks.

Ben

Error Trapping
Trying to connect between 2 winsock controls and the connectionrequest event isn't even firing. Here is some error trapping I did, don't know if this will help but when I trap the sckError this is the results of my query.....

[Client]
wsC.State= 9 - sckError
wsC.RemoteHost= 192.168.1.102
wsC.RemotePort= 3030 - assigned
wsC.LocalPort= 2693 - random

[Server]
wsS(FirstFreeSocket).State= 2 - listening
wsS(FirstFreeSocket).RemoteHost=
wsS(FirstFreeSocket).RemotePort= 0
wsS(FirstFreeSocket).LocalPort= 3030 -assigned

Copyright 2005-08 www.BigResource.com, All rights reserved