实时错误,没有为命令对象设置命令!
运行程序时,这个错误偶然会出现!! 错误光标指在:
If Not IsNull(personReadRec.Fields("cname")) Thenlbduty.Caption = personReadRec.Fields("pduty")End If有高手知道是什么原因吗?
检查了好几遍代码,没有错的。。

解决方案 »

  1.   

    你改成string类型判断:If trim(format(personReadRec.Fields("cname")))<>"" Then     lbduty.Caption = format(personReadRec.Fields("pduty")) End If 
      

  2.   

    个人觉得那是因为personReadRec.Fields("pduty") 造成的,因为当它不为NULL的时候不会出现那个错误,那应该怎么判断呢?
      

  3.   

    If (personReadRec.Fields("cname") & "" ) <>"" Then      lbduty.Caption = format(personReadRec.Fields("pduty"))  End If  
      

  4.   

    和上面一样,用一下format格式化为文本格式,或者:
    lbduty.Caption = personReadRec.Fields("pduty") & vbnullstring道理一样  
      

  5.   

    2楼的If trim(format(personReadRec.Fields("cname"))) <>"" Then  
    这样还是出错!
    我现在想的唯一方法是建数据库时默认写入一个“”空值,这样数据库中就不为NULL了~~不知这样对不对?
      

  6.   

    If (personReadRec.Fields("cname") & "" )  <>"" Then       lbduty.Caption = personReadRec.Fields("pduty")& ""   End If   以前就是这样处理的
      

  7.   

    如果是null引发的错误,你上面的写法应该没问题
    看你错误提示,也应该是NULL问题吧
      

  8.   

    若想添加时写入NULL,在添加前判断是否=“”,是则 “栏位”= NUll 
      

  9.   

    你的字段cname应该是文本类型吧?转换成文本格式判断,不要用isnull
      

  10.   

    实际上长度为零的字符串和null是不同的,所以如果你cname字段是文本类型,正确的做法就是转换成文本格式,判断是不是零长度字符串
      

  11.   

    If Not IsNull(personReadRec.Fields("cname")) Then 
    --------------------------
    这条语句错在IsNULL(表达式),我觉得这里有问题
    你可以试验用VarName=personReadRec.Fields("cname")
    然后在用这条测试语句
    If Not IsNull(VarName)Then 
      

  12.   

    如果是vachar,如2楼在VB用中format转换判断也不行?还是一样的错误提示?
      

  13.   

    好像没有错误了
    不知道是因为正确了还是错误未激发!
    我下一句:
    If Not IsNull(personReadRec.Fields("pduty")) Thenlbduty.Caption = personReadRec.Fields("pduty")
    Else
    lbcompany.Caption = ""
    End If这样判断也没出错呀! 
      

  14.   

    pduty是什么数据类型?不是varchar吧?
      

  15.   

    实际上你不管字段类型,给控件赋值的时候,如果不是需要,可以什么判断都不要加,直接:
    lbduty.Caption = format(personReadRec.Fields("pduty"))
    或者
    lbduty.Caption = personReadRec.Fields("pduty") & vbnullstring
      

  16.   

    varchar类型!
    现在换回一开始的代码也没出错啦!
    那个错误是偶然出现的!。。
    怎么回事呀!万一拿到别的电脑运行又出错呢?
      

  17.   

    这个不好说,也有可能返回了空记录集吧?
    试试在赋值前加这样一个判断:
    if (not personReadRec.eof) and (not personReadRec.bof) then
        lbduty.Caption = format(personReadRec.Fields("pduty")) 
    end if
      

  18.   

    Null值可以这样来处理'将NULL值替换为空
    Public Function RepNull(ByVal strIn As Variant) As String
        If IsNull(strIn) Or strIn = Empty Then
            RepNull = ""
        Else
            RepNull = CStr(strIn)
        End If
    End Function