RunTime error 91 : object variable or with block variable not set

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukh13
    New Member
    • Jul 2015
    • 1

    #1

    RunTime error 91 : object variable or with block variable not set

    I am getting Run time error 91 in below ** area.I couldn't figure it out where is the problem. What i try is, to avoid to enter duplicate pin number.

    Code:
    Public Function Custom_PIN(ByVal TableName As String, _
        ByRef EmployeeCode As String, ByVal FieldName As String, ByVal DataToCheck As String, _
        Optional ByVal CodeFieldName As String = Empty, Optional ByVal CodeFieldValue As String = Empty) As Boolean
    
    Dim lstrSQL1 As String
    Dim lrsTemp1 As ADODB.Recordset
    
        lstrSQL1 = " Select  " & FieldName & "  from  " & TableName & " Where PIN_NO =" & DataToCheck & ""
        'MsgBox (lstrSQL2)
    
        If Len(Trim$(CodeFieldName)) <> 0 And Len(Trim$(CodeFieldValue)) <> 0 Then
           lstrSQL1 = lstrSQL1 & " AND " & CodeFieldName & " <> '" & CodeFieldValue & "'"
        End If
    
        Set lrsTemp1 = cObjDBConn.ExecuteSQL(lstrSQL1)
    
        If lrsTemp1 Is Nothing Then
            Custom_PIN = False
        ElseIf Not (lrsTemp1.BOF And lrsTemp1.EOF) Then
            Custom_PIN = True
            lrsTemp1.MoveFirst
            EmployeeCode = lrsTemp1.Fields("EMPLOYEE_CODE")
        ElseIf lrsTemp1.RecordCount = 0 Then
            Custom_PIN = False
        Else
            Custom_PIN = False
        End If
    
        ***If lrsTemp1.State = adStateOpen Then lrsTemp1.Close
        Set lrsTemp1 = Nothing ****
    
    Exit Function
    
    ErrorHandle:
        Custom_PIN = False
    End Function
    Here is my calling Code

    Code:
    If gobjValidation.Custom_PIN(fstrTableName, gEmployeeCode, "EMPLOYEE_CODE", _
                Trim$(TxtPINno.text)) = True Then
                MsgBox (gEmployeeCode)
    Last edited by Rabbit; Jul 27 '15, 04:44 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
Working...