还是不行啊!
请看修改后的代码:
Private Sub Command4_Click()
If (Rst.State = adStateOpen) Then
Rst.Close
End If
Rst.CursorLocation = adUseClient
Rst.Open "Select * From 亲戚信息", Conn, adOpenKeyset, adLockPessimistic
Text1.Locked = False
Text2.Locked = False
Text3.Locked = False
Text4.Locked = False
Text5.Locked = False
Text6.Locked = False
Text7.Locked = False
Text8.Locked = False
Text9.Locked = False
Text10.Locked = False
Text11.Locked = False
Text12.Locked = False
Text13.Locked = False
Text14.Locked = False
Text15.Locked = False
Text17.Text = Rst.AbsolutePosition
Rst.Update
MsgBox "修改成功!"
Text16.Text = Rst.RecordCount
CmdAdd.Visible = True
Command2.Visible = False
Command4.Visible = False
Command3.Visible = True
Command3.Enabled = True
CmdDelete.Enabled = True
CmdPrevious.Enabled = True
CmdNext.Enabled = True
CmdFirst.Enabled = True
CmdLast.Enabled = True
End Sub
要不你试试只用核心代码,把其他的全部去掉再试试怎么样?
Private Sub Command4_Click()
Text1.Locked = False
Text2.Locked = False
Text3.Locked = False
Text4.Locked = False
Text5.Locked = False
Text6.Locked = False
Text7.Locked = False
Text8.Locked = False
Text9.Locked = False
Text10.Locked = False
Text11.Locked = False
Text12.Locked = False
Text13.Locked = False
Text14.Locked = False
Text15.Locked = False
End Sub
因为你修改一个已经存在的记录,记录集一定是打开的,其他的属性也都是初始化状态
先点击“修改”控件,出现“确定”控件,修改完毕后,再点击“确定”
我又参照了某高手的“修改”控件的代码如下:
Private Sub Command3_Click()(“确定”控件)
Command1(“修改”控件).Visible = False
On Error Resume Next
If Text1.Text = "" Then
MsgBox "不能为空!"
Text1.SetFocus
Rst.Fields("jbgz").Value = Trim(Text1.Text)
Exit Sub
Rst.Update
End If
If Text2.Text = "" Then
MsgBox "不能为空!"
Text2.SetFocus
Rst.Fields("zcgz").Value = Trim(Text2.Text)
Exit Sub
Rst.Update
End If
If Text3.Text = "" Then
MsgBox "不能为空!"
Text3.SetFocus
Rst.Fields("zwgz").Value = Trim(Text3.Text)
Exit Sub
Rst.Update
End If
If Text4.Text = "" Then
MsgBox "不能为空!"
Text4.SetFocus
Rst.Fields("glgz").Value = Trim(Text4.Text)
Exit Sub
Rst.Update
End If
If Text5.Text = "" Then
MsgBox "不能为空!"
Text5.SetFocus
Rst.Fields("bz").Value = Trim(Text5.Text)
Exit Sub
Rst.Update
End If
Rst.Update
MsgBox "修改成功!"
Command1.Visible = True
End Sub
但还是不行!
通过上下翻页,见到某位置的记录需要修改,点“修改”(Command3)按钮,使TEXT恢复ENABLED为TRUE,在上面修改完毕后,点“确定”(Command10)按钮!
我最近又改写了代码如下:
Private Sub Command10_Click()
On Error Resume Next
If (Rst.State = adStateOpen) Then
Rst.Close
End If
Rst.CursorLocation = adUseClient
Rst.Open "Select * From zymc1", Conn, adOpenKeyset, adLockPessimistic
Rst.MovePrevious
Rst.Delete
Rst.AddNew
Rst.Fields("dm").Value = Text1.Text
Rst.Fields("xm").Value = Text2.Text
Rst.Fields("xb").Value = Text3.Text
Rst.Fields("ll").Value = Text4.Text
Rst.Fields("cjgz").Value = Text5.Text
Rst.Fields("gl").Value = Text6.Text
Rst.Fields("zc").Value = Text7.Text
Rst.Fields("zw").Value = Text8.Text
Rst.Fields("zzmm").Value = Text9.Text
Rst.Fields("zz").Value = Text10.Text
Rst.Fields("lxdh").Value = Text11.Text
Rst.Fields("bz").Value = Text12.Text
Rst.Update
MsgBox "修改成功!"
Command3.Visible = True
Command10.Visible = False
End Sub
Private Sub Command3_Click()
Command10.Visible = True
Command5.Visible = False
Command3.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text6.Enabled = True
Text7.Enabled = True
Text8.Enabled = True
Text9.Enabled = True
Text10.Enabled = True
Text11.Enabled = True
Text12.Enabled = True
End Sub
但执行后,发现,把前面的不想修改的记录给删除了,原来错误的记录仍然还在!新添了修改后的记录!
后来,把
Rst.MovePrevious
Rst.Delete
Rst.AddNew
反复调整,还是不行!
始终指针指不到准确位置上去!