下面是我编译出错的一个程序段:
Private Sub btnReadTags_Click()
   Dim intRetValue As Integer
   Dim intmyval As String
   Dim myval As String
   intRetValue = Communication.ReadAllTags(txtUseAntenna)
   If intRetValue = 1 Then
      ShowMessage "读取标签成功!"
      Dim nCounter As Integer
      ShowMessage "显示标签读取列表:"
      For nCounter = 0 To 2 'intCurrentReaderReads - 1
          intmyval = Communication.GetCurrentTagid(nCounter)
      ShowMessage intmyval
      '自动更新数据库
      Adodc1.RecordSource = "select * from 商品信息表  "
      'where 商品EPC码='" + Communication.GetCurrentTagid(nCounter) + "'"
      'Adodc1.Refresh
      If inmyval = Adodc1.Recordset.Fields("商品EPC码") Then
         myval = MsgBox("该编码已经存在,是否要添加到数据库?", vbYesNo, "提示!")
         If myval = vbYes Then
            Adodc1.Recordset.Fields("商品EPC码") = intmyval
            Adodc1.Recordset.Update
         End If
      Else
         Adodc1.Recordset.Fields("商品EPC码") = intmyval
         Adodc1.Recordset.Update
      End If
      Next nCounter
      'intCurrentReaderReads = 0
   Else
     ShowMessage "读取标签失败! 错误代码: " & intRetValue
   End If
End Sub
编译光标在'If inmyval = Adodc1.Recordset.Fields("商品EPC码") Then'位置上报错:“实时错误'91',对象变量或with块变量未设置"小弟刚刚学习,请各位达人赐教,不胜感激!!!

解决方案 »

  1.   

    'Adodc1.Refresh这句不注释呢?
    或者是你没有设置Adodc1的ConnectionString
      

  2.   

    'Adodc1.Refresh不注释我试过了,同样的错误。
    Adodc1的ConnectionString都设置好了。
      

  3.   

    我怎么看来看去没看到如何打开adodc这个数据库阿,紧紧只设定了adodc的RecordSource ,而没有open阿
      

  4.   

    Dim adore As New ADODB.Recordset
    adore.Open SQL, Connstr, adOpenDynamic, adLockBatchOptimistic
      

  5.   

    那你出错的时候 看一下 Adodc1 和 Adodc1.Recordset是不是nothing
      

  6.   

    我用ADODC1.ConnectionString绑定了啊。
      

  7.   

    或者是你数据库里本来没有记录 所以 Adodc1.Recordset.Fields("商品EPC码") 是NULL
      

  8.   

    判断一下Adodc1.Recordset是否为空