I got this error "object variable or with block variable not set"
Below is my code
Module 1

Public Function tracePackageError(Optional oPackage As DTS.Package) As String
Dim ErrorCode As Long
Dim ErrorSource As String
Dim ErrorDescription As String
Dim ErrorHelpFile As String
Dim ErrorHelpContext As Long
Dim ErrorIDofInterfaceWithError As String
Dim i As Integer

        For i = 1 To oPackage.Steps.Count

                If oPackage.Steps(i).ExecutionResult = DTSStepExecResult_Failure Then
                        oPackage.Steps(i).GetExecutionErrorInfo ErrorCode, ErrorSource, ErrorDescription, _
                                        ErrorHelpFile, ErrorHelpContext, ErrorIDofInterfaceWithError                      
        tracePackageError = oPackage.Steps(i).Name & " failed" & vbCrLf & ErrorSource & vbCrLf & ErrorDescription
    Exit Function
                End If
        Next i
End Function

Form 1 call my function

    Private Sub Command1_Click()

       If tracePackageError <> "" Then

        MsgBox "error occured:" & vbCrLf & tracePackageError

       End If
    End Sub

Error : "object variable or with block variable not set"

You didn't pass tracePackageError an object but you are trying to reference it from within tracePackageError so you get an error. See vb.net optional parameters.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.