| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1004 人关注过本帖
标题:我的“修改”(COMAND4)控件代码怎么写啊?
取消只看楼主 加入收藏
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
结帖率:84.62%
收藏
 问题点数:0 回复次数:8 
我的“修改”(COMAND4)控件代码怎么写啊?


我是这样写的:
Private Sub Command4_Click()

'Set Rst = CreateObject("ADODB.Recordset")
If (Rst.State = adStateOpen) Then
Rst.Close
End If
Rst.CursorLocation = adUseClient
Rst.Open "Select * From 亲戚信息", Conn, adOpenKeyset, adLockPessimistic

Rst.Fields("姓名").Value = Text1.Text
Rst.Fields("单位名称").Value = Text2.Text
Rst.Fields("办公电话").Value = Text3.Text
Rst.Fields("办公电话二").Value = Text4.Text
Rst.Fields("手机").Value = Text5.Text
Rst.Fields("手机二").Value = Text6.Text
Rst.Fields("宅电").Value = Text7.Text
Rst.Fields("宅电二").Value = Text8.Text

Rst.Fields("电子邮箱").Value = Text9.Text
Rst.Fields("电子邮箱二").Value = Text10.Text
Rst.Fields("QQ号").Value = Text11.Text
Rst.Fields("QQ号二").Value = Text12.Text
Rst.Fields("地址").Value = Text13.Text
Rst.Fields("邮政编码").Value = Text14.Text
Rst.Fields("其他").Value = Text15.Text

Rst.Update

MsgBox "修改成功!"
Text16.Text = Rst.RecordCount
CmdAdd.Visible = True
CmdAdd.Enabled = 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

当点COMAND4时,发现新记录在第一条上,要修改的仍然存在,仍然在那个位置,而原来的第一条缺消失了!!!

如何使指针指向指定位置进行修改呢?

具体代码如何编写呢?

搜索更多相关主题的帖子: 控件 代码 
2006-11-07 14:09
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
收藏
得分:0 

If (Not Rst.EOF) Then
Rst.MoveNext
If (Not Rst.EOF) Then
Rst.MovePrevious
Text1.Text = Rst.Fields("姓名").Value
...
...
...
Text17.Text = Rst.AbsolutePosition
Rst.Update

MsgBox "修改成功!"
Text16.Text = Rst.RecordCount

这样执行后,没有任何变化!

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

我改编写的代码如下:

Private Sub Command4_Click()

If MsgBox("要修改吗?", vbExclamation + vbYesNo) = vbYes Then
Rst.Delete
MsgBox "修改成功!"
Rst.AddNew
Else
End If

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-10 19:20
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
收藏
得分:0 
再帮我修改下!!!
好么?
2006-11-10 20:27
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
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.016789 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved