I am not sure if this is what you are after. but say you have a recordset and you are not sure if the recordset exist or opened then...
if (not rs is nothing) then
if (rs.state = adstateopen) then rs.close
set rs = nothing
end if
you could do the same for connections. but sometimes before you close recordsets you may want to update/cancelupdate and if before close connections, you may want to commit/rollback tansactions.
Main Topics
Browse All Topics





by: virus_patPosted on 2003-08-25 at 21:00:04ID: 9221217
Here is the code if anyone wants to see:
er
********** ********** ********** ********** ********** ********** ********** ********** "delete from tblintfaxinlog" ********** ********** ********** ********** ********** ********** ********** ********** erver, COMMPROTOCOL_TCPIP, lError) NT_0, lUserObj)
T_0, lFaxObj) NT_0, lHistoryObj)
serList, lUserObj) Obj, RFO_ULE1_USERID)) 'UserID , lUserInfoObj) bj, RFO_UI10_ST_DIDNUM)
ENT_0, lFaxObj) axList, lFaxObj) 'get the first fax in the list
lFaxInfoObj) j, RFO_FI10_FROM_NAME) j, RFO_FI10_UNIQUE_ID) j, RFO_FI10_NUMPAGES, inumpages) j, RFO_FI10_FAX_TERMSTAT, itermstatus) j, RFO_FI10_FAX_ERROR_CODE, iErrCode)
, hFax, lHistoryList) MENT_0, lHistoryObj) istoryList , lHistoryObj) 'get the first fax in the list j, RFO_HLE0_TRX_ANI) MENT_0, lHistoryObj) storyList, lHistoryObj)
s) s)
j, RFO_FI10_TO_CITYSTATE, "FAXLOGGED") --******** ********** ********** ****------ ---------- ---------- ------ --******** ********** ********** ****------ ---------- ---------- ------ ENT_0, lFaxObj) xList, lFaxObj) MENT_0, lUserObj) erList, lUserObj)
er: Count > 0) Then tem(0).Des cription tem(0).Des cription lear
Function GenerateRcvdFaxLog() As String
54 On Error GoTo GenerateRcvdFaxLogErrHandl
Dim lError As Long
Dim hServer As Long 'RFax server handle
Dim lUserList As Long 'user list
Dim lUserObj As Long 'user object
Dim lUserInfoObj As Long
Dim lFaxList As Long 'fax list
Dim lFaxObj As Long 'fax object
Dim lFaxInfoObj As Long 'fax info object
Dim hFax As Long 'fax handle
Dim lHistoryList As Long 'fax history list
Dim lHistoryObj As Long 'fax history object
55 hServer = 0
56 lUserList = 0
57 lUserObj = 0
58 lUserInfoObj = 0
59 lFaxList = 0
60 lFaxObj = 0
61 lFaxInfoObj = 0
62 hFax = 0
63 lHistoryList = 0
64 lHistoryObj = 0
Dim userid As String 'user ID
Dim suserfaxnum As String
Dim istatus As Integer
Dim suniqueid As String
Dim isANIValid As Integer
Dim ANI As String
Dim inumpages As Integer
Dim lRcvdTime As Long
Dim sRcvdDateTime As String
Dim iYear As Integer, iMonth As Integer, iDay As Integer, iHour As Integer, iMin As Integer, iSec As Integer
Dim itermstatus As Integer
Dim iErrCode As Integer
Dim ltranstime As Long
Dim sEmailStatus As String
65 suserfaxnum = ""
66 userid = ""
67 istatus = 0
68 ANI = ""
69 suniqueid = ""
70 inumpages = 0
71 lRcvdTime = 0
72 sRcvdDateTime = ""
73 iYear = 0
74 iMonth = 0
75 iDay = 0
76 iHour = 0
77 iMin = 0
78 iSec = 0
79 iErrCode = 0
80 ltranstime = 0
81 isANIValid = 0
82 sEmailStatus = ""
Dim m_TransactionConn As ADODB.Connection
83 Set m_TransactionConn = New ADODB.Connection
Dim strConn As String
84 strConn = "Provider=sqloledb;Data Source=" & DBServer & ";Initial Catalog=" & DBDatabase & ";User ID=" & DBUserID & ";Password=" & DBPassword & ";"
85 m_TransactionConn.Open strConn
86 If (Not (m_TransactionConn Is Nothing)) Then
87 If (m_TransactionConn.State = adStateClosed) Then
88 ErrorLog "error connecting to database: " & DBServer & ", in module GenerateRcvdFaxLog"
89 GenerateRcvdFaxLog = "error connecting to database: " & DBServer & ", in module GenerateRcvdFaxLog"
Exit Function
End If
Else
90 ErrorLog "error connecting to database: " & DBServer & ", in module GenerateRcvdFaxLog"
91 GenerateRcvdFaxLog = "error connecting to database: " & DBServer & ", in module GenerateRcvdFaxLog"
Exit Function
End If
Dim strSQL As String
92 strSQL = "tblIntFaxInLog"
Dim rsData As ADODB.Recordset
93 Set rsData = New ADODB.Recordset
94 rsData.CursorType = adOpenKeyset
95 rsData.LockType = adLockOptimistic
96 rsData.Open strSQL, m_TransactionConn
97 If (Not (rsData Is Nothing)) Then
98 If (rsData.State = adStateClosed) Then
99 ErrorLog "error opening table: tblIntFaxInLog, in module GenerateRcvdFaxLog"
100 GenerateRcvdFaxLog = "error opening table: tblIntFaxInLog, in module GenerateRcvdFaxLog"
Exit Function
End If
Else
101 ErrorLog "error opening table: tblIntFaxInLog, in module GenerateRcvdFaxLog"
102 GenerateRcvdFaxLog = "error opening table: tblIntFaxInLog, in module GenerateRcvdFaxLog"
Exit Function
End If
'*************************
'remember to remove this line later
'm_TransactionConn.Execute
'*************************
103 DebugLog ("start to generate log for incoming faxes")
104 hServer = RFaxCreateServerHandle(RFS
105 If ((lError = RFAX_SUCCESS) And (hServer <> 0)) Then 'obtained the server handle successfully
106 DebugLog ("connected to fax server: " & RFServer)
'Create all the objects needed, exit the function if fail to create them
107 lError = RFVB_New(RFO_USERLISTELEME
108 If (lError <> RF2VB_SUCCESS) Then
109 ErrorLog "error occured when creating user object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
110 RFaxCloseServerHandle (hServer)
111 GenerateRcvdFaxLog = "error occured when creating user object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
Exit Function
End If
112 lError = RFVB_New(RFO_USERINFO_10, lUserInfoObj)
113 If (lError <> RF2VB_SUCCESS) Then
114 ErrorLog "error occured when creating user info object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
115 RFaxCloseServerHandle (hServer)
116 RFVB_Delete (lUserObj)
117 GenerateRcvdFaxLog = "error occured when creating user info object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
Exit Function
End If
118 lError = RFVB_New(RFO_FAXLISTELEMEN
119 If (lError <> RF2VB_SUCCESS) Then
120 ErrorLog "error occured when creating fax object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
121 RFaxCloseServerHandle (hServer)
122 RFVB_Delete (lUserObj)
123 RFVB_Delete (lUserInfoObj)
124 GenerateRcvdFaxLog = "error occured when creating fax object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
Exit Function
End If
125 lError = RFVB_New(RFO_FAXINFO_10, lFaxInfoObj)
126 If (lError <> RF2VB_SUCCESS) Then
127 ErrorLog "error occured when creating fax info object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
128 RFaxCloseServerHandle (hServer)
129 RFVB_Delete (lUserObj)
130 RFVB_Delete (lUserInfoObj)
131 RFVB_Delete (lFaxObj)
132 GenerateRcvdFaxLog = "error occured when creating fax info object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
Exit Function
End If
133 lError = RFVB_New(RFO_HISTLISTELEME
134 If (lError <> RF2VB_SUCCESS) Then
135 ErrorLog "error occured when creating history object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
136 RFaxCloseServerHandle (hServer)
137 RFVB_Delete (lUserObj)
138 RFVB_Delete (lUserInfoObj)
139 RFVB_Delete (lFaxObj)
140 RFVB_Delete (lFaxInfoObj)
141 GenerateRcvdFaxLog = "error occured when creating history object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
Exit Function
End If
142 lError = RFaxGetUserList(hServer, 1, lUserList) 'get the list of users
143 If (lError <> RFAX_SUCCESS) Then
144 ErrorLog "error while getting user list, in module GenerateRcvdFaxLog(), error: " & RFError2String(lError)
145 RFaxCloseServerHandle (hServer)
146 RFVB_Delete (lUserObj)
147 RFVB_Delete (lUserInfoObj)
148 RFVB_Delete (lFaxObj)
149 RFVB_Delete (lFaxInfoObj)
150 RFVB_Delete (lHistoryObj)
151 GenerateRcvdFaxLog = "error while getting user list, in module GenerateRcvdFaxLog(), error: " & RFError2String(lError)
Exit Function
End If
152 lError = RFaxListGetFirstElement(lU
153 While (lError = RFAX_SUCCESS)
154 userid = ""
155 suserfaxnum = ""
156 userid = Trim(RFVB_GetBString(lUser
157 lError = RFVB_Clear(RFO_USERINFO_10
158 lError = RFaxLoadUser2(hServer, 1, 0, userid, "", "", 0, 0, lUserInfoObj)
159 If (lError <> RFAX_SUCCESS) Then
160 ErrorLog "error loading user info for user: " & userid & ", in module GenerateRcvdFaxLog(), error: " & RFError2String(lError)
Else
161 suserfaxnum = RFVB_GetBString(lUserInfoO
End If 'check if the user info is loaded successfully
162 lError = RFaxGetFaxList(hServer, userid, 0, 0, 1, lFaxList) 'get the list of faxes for the user, 2 means get only sent faxes
163 If (lError <> RFAX_SUCCESS) Then 'there are faxes for the user
164 If (lError <> RFAXERR_NOTFOUND) Then
165 DebugLog ("failed to obtain fax list from user: " & userid & ", error: " & RFError2String(lError))
End If
Else
166 DebugLog ("obtained user fax list successfully, for user: " & userid)
167 lError = RFVB_Clear(RFO_FAXLISTELEM
168 lError = RFaxListGetFirstElement(lF
169 If lError <> RFAX_SUCCESS Then
170 DebugLog "there is no fax for user: " & userid
Else
171 While (lError = RFAX_SUCCESS) 'loop thru the faxes in the fax list
172 istatus = 0
173 lError = RFVB_GetInteger(lFaxObj, RFO_FLE0_FAX_STATUS, istatus) 'get status of the fax
174 If (lError <> RF2VB_SUCCESS) Then
175 DebugLog "error getting fax status, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
Else
176 ANI = ""
177 suniqueid = ""
178 inumpages = 0
179 lRcvdTime = 0
180 sRcvdDateTime = ""
181 iYear = 0
182 iMonth = 0
183 iDay = 0
184 iHour = 0
185 iMin = 0
186 iSec = 0
187 iErrCode = 0
188 ltranstime = 0
189 isANIValid = 0
190 sEmailStatus = ""
191 If ((istatus = FAXSTAT_DONE_OK) Or (istatus = FAXSTAT_DONE_ERROR)) Then
192 hFax = 0
193 lError = RFVB_GetLong(lFaxObj, RFO_FI10_HANDLE, hFax) 'get the fax handle
194 If (lError <> RF2VB_SUCCESS) Then
195 DebugLog "error getting fax handle, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
Else
196 lError = RFVB_Clear(RFO_FAXINFO_10,
197 lError = RFaxLoadFax(hServer, hFax, 0, 0, lFaxInfoObj) 'load the fax info into the lNewObj
198 If ((lError <> RFAX_SUCCESS) And (lError <> RFAXERR_NOTFOUND)) Then
199 DebugLog "error getting fax info, in module GenerateRcvdFaxLog(), error: " & RFError2String(lError)
Else
200 sEmailStatus = RFVB_GetBString(lFaxInfoOb
201 sEmailStatus = Trim(sEmailStatus)
202 If ((istatus = FAXSTAT_DONE_ERROR) Or ((sEmailStatus <> "") And (Len(sEmailStatus) > 0) And ((UCase(sEmailStatus)) <> "EMAILPENDING"))) Then
203 suniqueid = RFVB_GetBString(lFaxInfoOb
204 lError = RFVB_GetInteger(lFaxInfoOb
205 If (lError <> RF2VB_SUCCESS) Then
206 DebugLog "error getting number of pages for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
End If
207 lError = RFVB_GetInteger(lFaxInfoOb
208 If (lError <> RF2VB_SUCCESS) Then
209 DebugLog "error getting termination status for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
210 itermstatus = 0
End If
211 lError = RFVB_GetInteger(lFaxInfoOb
212 If (lError <> RF2VB_SUCCESS) Then
213 DebugLog "error getting termination status for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
214 iErrCode = 0
End If
215 lError = RFVB_GetLong(lFaxInfoObj, RFO_FI10_SEND_TIME, ltranstime)
216 If (lError <> RF2VB_SUCCESS) Then
217 DebugLog "error getting transmission time for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
218 ltranstime = 0
End If
219 lError = RFaxGetHistoryList(hServer
220 If (lError <> RFAX_SUCCESS) Then
221 DebugLog "error getting history list for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RFError2String(lError)
Else
222 lError = RFVB_Clear(RFO_HISTLISTELE
223 lError = RFaxListGetFirstElement(lH
224 While (lError = RFAX_SUCCESS) 'loop thru the history list elements
Dim histType As Byte
225 lError = RFVB_GetByte(lHistoryObj, RFO_HLE0_TYPE, histType)
226 If (lError <> RF2VB_SUCCESS) Then
227 DebugLog "error getting history type for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
Else
228 If ((histType = HISTTYPE_TXRXINFO) Or (histType = HISTTYPE_SECUREDOCS)) Then 'only get the info if it is transmission history type
229 RFVB_GetInteger lHistoryObj, RFO_HLE0_TRX_FLAGS, isANIValid
230 If ((isANIValid > 3 And isANIValid < 8) Or (isANIValid > 11 And isANIValid < 16)) Then
231 ANI = RFVB_GetBString(lHistoryOb
Else
232 ANI = ""
End If 'check if the ANI is valid
233 lError = RFVB_GetLong(lHistoryObj, RFO_HLE0_DATETIME, lRcvdTime)
234 If (lError <> RF2VB_SUCCESS) Then
235 DebugLog "error getting transmission history time for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
236 sRcvdDateTime = ""
Else
237 If (lRcvdTime > 0) Then
238 RFaxCTimeToValues lRcvdTime, iYear, iMonth, iDay, iHour, iMin, iSec
239 sRcvdDateTime = iYear & "/" & iMonth & "/" & iDay & " " & iHour & ":" & iMin & ":" & iSec
Else
240 sRcvdDateTime = ""
End If 'double check if tranmission time is valid
End If 'check if transmission time is ok
End If 'only get the info if it is transmission or secure doc history type
End If 'check if getting the history type is ok
241 lError = RFVB_Clear(RFO_HISTLISTELE
242 lError = RFaxListGetNextElement(lHi
243 Wend 'loop thru the history list elements
End If 'test whether the history list is obtained successfully
244 RFaxCloseListHandle (lHistoryList) 'close the history list
245 lHistoryList = 0
246 If (sRcvdDateTime = "") Then
247 sRcvdDateTime = "1900/1/1 0:0:0"
End If
248 rsData.AddNew
249 rsData!userid = userid
250 rsData!FaxNo = suserfaxnum
251 rsData!RightFaxJobID = suniqueid
252 If (ANI <> "") Then
253 rsData!Caller = ANI
End If
254 rsData!CallTime = sRcvdDateTime
255 rsData!NoOfPage = inumpages
256 rsData!Duration = ltranstime
257 If (istatus = FAXSTAT_DONE_OK) And ((UCase(sEmailStatus)) = "EMAILSUCCESSFUL") Then
258 rsData!callstatus = "S"
259 ElseIf (istatus <> FAXSTAT_DONE_OK) Then
Dim errString As String
260 rsData!callstatus = "F"
261 If ((itermstatus > 0) And (itermstatus < 24)) Then
262 errString = TermCode2String(itermstatu
263 rsData!Error = errString
Else
264 errString = ErrCode2String(iErrCode)
265 rsData!Error = errString
End If
Else
Dim errString2 As String
266 rsData!callstatus = "F"
267 If ((itermstatus > 0) And (itermstatus < 24)) Then
268 errString2 = TermCode2String(itermstatu
269 rsData!Error = errString2
Else
270 errString2 = ErrCode2String(iErrCode)
271 rsData!Error = errString2
End If
272 If ((sEmailStatus <> "EMAILSUCCESSFUL") And (sEmailStatus <> "")) Then
273 rsData!Error = sEmailStatus
End If
End If
274 rsData!icarestatus = "P"
275 rsData!creationdate = Now
276 rsData.Update
' lError = RFVB_SetBString(lFaxInfoOb
'-------------------------
'UNCOMMENT THESE LINES WHEN FINISHED
277 If (IsDeleteAsLogged = True) Then
278 lError = RFaxDeleteFax(hServer, hFax)
279 If (lError <> RF2VB_SUCCESS) Then
280 ErrorLog "error deleting fax after log: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
End If
End If
'-------------------------
End If 'check billinfo2, only log the fax if it is not ""
End If 'check getting fax info
End If 'check getting fax handle
End If 'filter out the ones that are DoneOK or DoneError
End If 'check getting fax status
281 Sleep 100
282 lError = RFVB_Clear(RFO_FAXLISTELEM
283 lError = RFaxListGetNextElement(lFa
284 Wend 'Loop thru all incoming fax
285 RFaxCloseListHandle (lFaxList)
286 lFaxList = 0
End If
End If
287 lError = RFVB_Clear(RFO_USERLISTELE
288 lError = RFaxListGetNextElement(lUs
289 Wend 'loop thru all users
290 RFVB_Delete (lUserObj)
291 RFVB_Delete (lUserInfoObj)
292 RFVB_Delete (lFaxObj)
293 RFVB_Delete (lFaxInfoObj)
294 RFVB_Delete (lHistoryObj)
295 lUserObj = 0
296 lUserInfoObj = 0
297 lFaxObj = 0
298 lFaxInfoObj = 0
299 lHistoryObj = 0
300 RFaxCloseListHandle (lUserList)
301 lUserList = 0
302 RFaxCloseServerHandle (hServer)
303 hServer = 0
Else
' DebugLog "Failed to connect to fax server: " + RFServer
304 rsData.Close
305 Set rsData = Nothing
306 m_TransactionConn.Close
307 Set m_TransactionConn = Nothing
308 GenerateRcvdFaxLog = "Failed to connect to fax server: " + RFServer
309 If (hServer <> 0) Then
310 RFaxCloseServerHandle (hServer)
End If
Exit Function
End If 'Login server??
311 rsData.Close
312 Set rsData = Nothing
313 m_TransactionConn.Close
314 Set m_TransactionConn = Nothing
315 GenerateRcvdFaxLog = "transaction log for recieved faxes generated successfully"
Exit Function
GenerateRcvdFaxLogErrHandl
316 If (m_TransactionConn.Errors.
' ErrorLog "database error occured, in module: GenerateRcvdFaxLog. Error: " & m_TransactionConn.Errors.I
317 GenerateRcvdFaxLog = "database error occured, error line: " & Erl & ", in module: GenerateRcvdFaxLog. Error: " & m_TransactionConn.Errors.I
318 m_TransactionConn.Errors.C
Else
'ErrorLog "error occured in module: GenerateRcvdFaxLog"
320 If Err.Number <> 0 Then
321 GenerateRcvdFaxLog = "error occured while generating received fax log, error line: " & Erl & ", in module: GenerateRcvdFaxLog, error: " & Err.Description
322 Err.Clear
Else
323 GenerateRcvdFaxLog = "unknown error occured while generating received fax log, error line: " & Erl & ", in module: GenerateRcvdFaxLog"
End If
End If
324 If (Not (rsData Is Nothing)) Then
325 If (rsData.State <> adStateClosed) Then
326 rsData.CancelUpdate
327 rsData.Close
End If
328 Set rsData = Nothing
End If
329 If (Not (m_TransactionConn Is Nothing)) Then
330 If (m_TransactionConn.State <> adStateClosed) Then
331 m_TransactionConn.Cancel
332 m_TransactionConn.Close
End If
333 Set m_TransactionConn = Nothing
End If
334 RFVB_Delete (lUserObj)
335 RFVB_Delete (lUserInfoObj)
336 RFVB_Delete (lFaxObj)
337 RFVB_Delete (lFaxInfoObj)
338 RFVB_Delete (lHistoryObj)
339 If (lHistoryList <> 0) Then
340 RFaxCloseListHandle (lHistoryList)
End If
341 If (lFaxList <> 0) Then
342 RFaxCloseListHandle (lFaxList)
End If
343 If (lUserList <> 0) Then
344 RFaxCloseListHandle (lUserList)
End If
345 If (hServer <> 0) Then
346 RFaxCloseServerHandle (hServer)
End If
End Function