以下代碼運行到If Not l_adorsClose.EOF Then就會報物件變數或 With 塊變數未設定的錯 百度以后將 Dim l_adorsClose As ADODB.Recordset 改為 Dim l_adorsClose As New ADODB.Recordset后又報3701,物件關閉時,不允許操作
求各位大佬幫忙
Dim l_sqlClose As String
Dim l_adorsClose As ADODB.Recordset
l_sqlClose = "select cld01 close_date,cld02 close_time,cld05 open_date from cld_file where cld03='Y'" 'B2B關帳時間表
Set l_adorsClose = exesql("B2B", l_sqlClose)
If Not l_adorsClose.EOF Then
l_CloseDate = l_adorsClose("close_date")
l_CloseTime = l_adorsClose("close_time")
l_OpenDate = l_adorsClose("open_date")
End If
l_CurrentDate = Format(Now(), "YYYYMMDD")
l_CurrentTime = Format(Now(), "HHMMSS")
'如果當前日期在關帳日期后,開帳日期前,就退出程式(關帳期間不運行)
If (l_CurrentDate = l_CloseDate And l_CurrentTime >= l_CloseTime) Or (l_CurrentDate > l_CloseDate And l_CurrentDate < l_OpenDate) Then
Exit Sub
End If
uj5u.com熱心網友回復:
exesql("B2B", l_sqlClose) 回傳值是個ADODB.Recordset物件?可以把 exesql("B2B", l_sqlClose) 的代碼貼上來看一下
uj5u.com熱心網友回復:
以下是對資料庫進行操作Public Function exesql(SYSID As String, ByVal sSQL As String) As ADODB.Recordset
'傳遞引數系統別,便于資料庫連接:
'MES表示MES資料庫連接字串;
'SAP表示SAP資料庫連接字串;
'B2B表示B2B資料庫連接字串;
'自身并以Reconderset物件的形式回傳,便于資料庫操作。
Dim cnn1 As New ADODB.Connection
Dim adors1 As New ADODB.Recordset
Dim arry() As String
'例外處理
On Error GoTo exesql_err
'用Split 函式產生各個字串的陣列
arry = Split(Trim$(sSQL))
'打開資料庫連接 By 不同的系統類別
Select Case UCase$(Trim$(SYSID))
Case "B2B"
cnn1.Open g_b2b
Case "SAP"
cnn1.Open g_sap
Case "MES"
cnn1.Open g_mes
Case "B2BDS1"
cnn1.Open g_b2bds1
End Select
'判斷SQL執行陳述句到除錯于那種操作
If InStr("INSERT,DELETE,UPDATE", UCase$(arry(0))) Then
cnn1.Execute sSQL
Else
With adors1
.CursorLocation = adUseClientBatch
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open sSQL, cnn1
' Set .ActiveConnection = Nothing
End With
Set exesql = adors1
End If
exesql_exit:
Set adors1 = Nothing
'cnn1.Close
Set cnn1 = Nothing
Exit Function
exesql_err:
Resume exesql_exit
' MsgBox Err.Description
End Function
uj5u.com熱心網友回復:
這代碼別人運行就正常 我運行就報錯 是不是我哪配置有問題uj5u.com熱心網友回復:
Set adors1 = Nothing你這句已經把物件設為nothing了,哪能回傳你想要的recordset啊
uj5u.com熱心網友回復:
那該怎么弄 主要我剛接手 這都是別人寫好的 不是太清楚怎么改 你能不能詳細說明一下
uj5u.com熱心網友回復:
exesql_exit:Set adors1 = Nothing
'cnn1.Close
Set cnn1 = Nothing
改成
exesql_exit:
'Set adors1 = Nothing
'cnn1.Close
'Set cnn1 = Nothing
試試
uj5u.com熱心網友回復:
請問你們用的是v6或vb.net ?轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/23382.html
標籤:VB基礎類
下一篇:VB.NET對CAD二次開發出現“加載型別庫/DLL 時出錯。 (例外來自 HRESULT:0x80029C4A (TYPE_E_CANTLOADLIBR”
