Private Sub Form_Load()
    Dim sSql As String
    Dim intCount As Integer
    Dim mrc As ADODB.Recordset
  
    
   
    If gintOmode = 1 Then
        Me.Caption = Me.Caption & "添加"
        
        '初始化物资名称
        txtSQL = "select DISTINCT yename from msurplus where yeaccount<>0"
        Set mrc = ExecuteSQL(txtSQL, MsgText)
        
        If Not mrc.EOF Then           '为什么这行有错啊?
            
                Do While Not mrc.EOF
                    cboItem(1).AddItem Trim(mrc!yename)
                    mrc.MoveNext
                Loop
                cboItem(1).ListIndex = 0
            
        Else
            MsgBox "仓库中没有物资!", vbOKOnly + vbExclamation, "警告"
            cmdSave.Enabled = False
            Exit Sub
        End If
        mrc.Close
        
        txtAccount = "0"
        txtValue = "0"
        txtNo = GetRkno
        txtBase = " "
                
    ElseIf gintOmode = 2 Then
       
        Set mrc = ExecuteSQL(txtSQL, MsgText)
        
        If mrc.EOF = False Then
            With mrc
                
                For intCount = 0 To 4
                    cboItem(intCount).AddItem .Fields(intCount + 1)
                    cboItem(intCount).ListIndex = 0
                Next intCount
                
                For intCount = 0 To 7
                    If Not IsNull(.Fields(intCount + 6)) Then
                        txtItem(intCount) = .Fields(intCount + 6)
                    End If
                Next intCount
                
                '保存更改数据
                txtAccount = !lyaccount
                txtValue = !lyvalue
                txtNo = !lyno
                txtBase = !lybase & " "
                
            End With
            
        End If
        mrc.Close
        Me.Caption = Me.Caption & "修改"
    End If
    
    mblChange = False
    
End Sub
为什么 If Not mrc.EOF Then  在那行有错啊,我vb初学,看不明白,

解决方案 »

  1.   

    Dim mrc As new ADODB.Recordset
      

  2.   

    Set mrc = ExecuteSQL(txtSQL, MsgText)
    你是没弄明白局部对象与全局的区别。ExecuteSQL里面定义的东西对外部是无效的。
    建议增加参数(引用方式)把记录集对象当参数传进去。
      

  3.   

    ExecuteSQL(txtSQL, MsgText)有问题
    应该是 ExecuteSQL = conn.Execute(txtSQL)
      

  4.   

    楼主看的是"Visual Basic 6.0 数据库系统开发实例导航"这书中的例子吧
    并且还是第六章"物资管理信息系统"
    代码是没有错误的,只是你得配置一FileDSN,并且名称得为:material,默认数据库也是为:Material
      

  5.   

    或者你把
    Public Function ConnectString() _
       As String
    'returns a DB ConnectString
       ConnectString = "FileDSN=material.dsn;UID=sa;PWD="
    End Function
    中的ConnectString = "FileDSN=material.dsn;UID=sa;PWD="
    改为:
       ConnectString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=material;Data Source=(local)"
    这样就可以不用配置File DNS