大家好,我是VB新手,接触一个多星期,困难重重啊,下面是小弟我的困难之一,希望高手们不吝赐教~代码如下,其中command1是添加功能,command6和command7分别是上一个和下一个功能其他的功能待写,添加功能是好使的,能添加上,只是担心有些情况会不适用,各位看看有没有缺陷关键的是上一个和下一个功能,怎么点都没反应,始终定位在初始的那一条记录或者刚添加上的记录上麻烦朋友们分析下是什么原因,在下先行谢过~Dim Rs As New ADODB.RecordsetPrivate Sub Form_Load()Dim Cn As New ADODB.Connection
Dim cnstr As String
Dim Sql As String
cnstr = "provider=sqloledb;User ID = sa;password = 880805;initial catalog = 小区物业管理;Data Source = WAXSNYBB\WAXSN"
Cn.Open cnstr
Sql = "select * from 业主信息"
Rs.CursorLocation = adUseClient
Rs.Open Sql, Cn, adOpenDynamic, adLockOptimistic
Text1.Text = Rs(0)
Text2.Text = Rs(1)
Text3.Text = Rs(2)
Text4.Text = Rs(3)
Text5.Text = Rs(4)
Text6.Text = Rs(5)
Text7.Text = Rs(6)
End SubPrivate Sub Command1_Click()
If Command1.Caption = "添加" Then
Command1.Caption = "确认"
Text1.Text = "": Text2.Text = "": Text3.Text = "": Text4.Text = ""
Text5.Text = "": Text6.Text = "": Text7.Text = ""
Text1.SetFocus
Else
Command1.Caption = "添加"
Rs.AddNew
Rs("业主编号") = Trim(Text1.Text)
Rs("业主姓名") = Trim(Text2.Text)
Rs("联系方式") = Trim(Text3.Text)
Rs("住宅面积") = Trim(Text4.Text)
Rs("家庭成员") = Trim(Text5.Text)
Rs("入住日期") = Trim(Text6.Text)
Rs("备注") = Trim(Text7.Text)
Rs.Update
End If
End SubPrivate Sub Command6_Click()
Rs.MovePrevious
If Rs.BOF Then
Rs.MoveFirst
End If
End SubPrivate Sub Command7_Click()
Rs.MoveNext
If Rs.EOF Then
Rs.MoveLast
End If
End Sub

解决方案 »

  1.   

    你所有的函数都没有错误处理
    on error ....至少需要加上这个
      

  2.   

    移动了指针后,你的textbox不会知道你指示的记录已经改变,所以你在moveprevious和movenext后要显示移动后的记录:
    在后面添加:
    Text1.Text = Rs(0)
    Text2.Text = Rs(1)
    Text3.Text = Rs(2)
    Text4.Text = Rs(3)
    Text5.Text = Rs(4)
    Text6.Text = Rs(5)
    Text7.Text = Rs(6)
      

  3.   

    请问具体操作是什么呢,我刚才按您提示在command6/7的end if 后边各加了一个rs.refresh执行后,点上一个/下一个,提示说未找到方法或数据成员,蓝色条定位在  .refresh上是什么原因呢,老师
      

  4.   


    就是代码有点太多了...您有办法可以使代码变得简单些么,是不是应该改动form load的代码呢?我没用adodc控件..