我的目標是測試一個記錄表,如果該特定記錄存在,則什麼都不做,否則做一些插入記錄。我寫了下面的SQL語句,試圖檢索特定的記錄錯誤:用SQL語句打開記錄集MsAccess
Update: Dim strSQL2 As String
Dim objRecordset As ADODB.Recordset
Dim BatchID As Long
Dim instrumentName As String
strSQL2 = "SELECT * FROM tblInstrumentInterfacelog " & _
"WHERE BatchID = " & BatchID & " " & _
"AND InstrumentName = '" & InstrumentName & "'"
Set objRecordset = CurrentDb.OpenRecordset(strSQL2, dbOpenDynaset, dbSeeChanges)
If objRecordset.RecordCount > 0 Then
Else
"logic to insert record"
End if
我在該行
Set objRecordset = CurrentDb.OpenRecordset(strSQL2, dbOpenDynaset, dbSeeChanges)
得到一個錯誤類型不匹配爲tblInstrumentInterfaceLog的模式是:
- [InstrumentInterfaceLogID] [int] IDENTITY(1,1)NOT NULL
- [InstrumentName] nvarchar NO牛逼NULL
- [BatchID] [INT] NOT NULL
- [文件名]爲nvarchar NOT NULL
我只需要幫上所提供的代碼,這是爲什麼類型不匹配的發生?
你在哪裏聲明objRecordset變量? –
添加了更多的聲明 – VictoriaJay
請參閱開放記錄集部分http://www.classanytime.com/mis333k/sjdaoadorecordsets.html – TMNT2014