| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1004 人关注过本帖
标题:我的“修改”(COMAND4)控件代码怎么写啊?
只看楼主 加入收藏
lhf391855540
Rank: 1
等 级:新手上路
帖 子:175
专家分:0
注 册:2006-10-14
收藏
得分:0 
楼主的意思不是要对已经存在的记录进行修改吗?
2006-11-12 13:56
lhf391855540
Rank: 1
等 级:新手上路
帖 子:175
专家分:0
注 册:2006-10-14
收藏
得分:0 
有一个例子,是这样的:
Private Sub cmd修改_Click()
Dim i As Integer
For i = 0 To 40
Text1(i).Locked = False
Next i
End Sub
2006-11-12 14:04
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
收藏
得分:0 

还是不行啊!
请看修改后的代码:
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

2006-11-12 14:41
lhf391855540
Rank: 1
等 级:新手上路
帖 子:175
专家分:0
注 册:2006-10-14
收藏
得分:0 

要不你试试只用核心代码,把其他的全部去掉再试试怎么样?
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
因为你修改一个已经存在的记录,记录集一定是打开的,其他的属性也都是初始化状态

2006-11-12 16:40
lhf391855540
Rank: 1
等 级:新手上路
帖 子:175
专家分:0
注 册:2006-10-14
收藏
得分:0 
修改后再进行保存
2006-11-12 16:49
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
收藏
得分:0 
还是不行!

请看看我的《上传仿制的有问题的数据库编写系统 》帖!
具体检查看看!

谢谢!
2006-11-13 13:42
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
收藏
得分:0 

先点击“修改”控件,出现“确定”控件,修改完毕后,再点击“确定”

我又参照了某高手的“修改”控件的代码如下:
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

但还是不行!

2006-11-26 22:27
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
收藏
得分:0 
执行后,还是原样未动!
2006-11-26 22:28
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
收藏
得分:0 

通过上下翻页,见到某位置的记录需要修改,点“修改”(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

反复调整,还是不行!

始终指针指不到准确位置上去!

2006-11-27 22:21
快速回复:我的“修改”(COMAND4)控件代码怎么写啊?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019410 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved