423,680 Members | 2,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,680 IT Pros & Developers. It's quick & easy.

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

P: 1
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.

Expand|Select|Wrap|Line Numbers
  1. Public Function Custom_PIN(ByVal TableName As String, _
  2.     ByRef EmployeeCode As String, ByVal FieldName As String, ByVal DataToCheck As String, _
  3.     Optional ByVal CodeFieldName As String = Empty, Optional ByVal CodeFieldValue As String = Empty) As Boolean
  4.  
  5. Dim lstrSQL1 As String
  6. Dim lrsTemp1 As ADODB.Recordset
  7.  
  8.     lstrSQL1 = " Select  " & FieldName & "  from  " & TableName & " Where PIN_NO =" & DataToCheck & ""
  9.     'MsgBox (lstrSQL2)
  10.  
  11.     If Len(Trim$(CodeFieldName)) <> 0 And Len(Trim$(CodeFieldValue)) <> 0 Then
  12.        lstrSQL1 = lstrSQL1 & " AND " & CodeFieldName & " <> '" & CodeFieldValue & "'"
  13.     End If
  14.  
  15.     Set lrsTemp1 = cObjDBConn.ExecuteSQL(lstrSQL1)
  16.  
  17.     If lrsTemp1 Is Nothing Then
  18.         Custom_PIN = False
  19.     ElseIf Not (lrsTemp1.BOF And lrsTemp1.EOF) Then
  20.         Custom_PIN = True
  21.         lrsTemp1.MoveFirst
  22.         EmployeeCode = lrsTemp1.Fields("EMPLOYEE_CODE")
  23.     ElseIf lrsTemp1.RecordCount = 0 Then
  24.         Custom_PIN = False
  25.     Else
  26.         Custom_PIN = False
  27.     End If
  28.  
  29.     ***If lrsTemp1.State = adStateOpen Then lrsTemp1.Close
  30.     Set lrsTemp1 = Nothing ****
  31.  
  32. Exit Function
  33.  
  34. ErrorHandle:
  35.     Custom_PIN = False
  36. End Function
  37.  
Here is my calling Code

Expand|Select|Wrap|Line Numbers
  1. If gobjValidation.Custom_PIN(fstrTableName, gEmployeeCode, "EMPLOYEE_CODE", _
  2.             Trim$(TxtPINno.text)) = True Then
  3.             MsgBox (gEmployeeCode)
Jul 27 '15 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.