如何使用seltop和selheight更新数据表子表单上的选定记录? [英] How to update selected records on a datasheet subform using seltop and selheight?

查看:42
本文介绍了如何使用seltop和selheight更新数据表子表单上的选定记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。


我可以使用位于主窗体上的命令按钮以什么方式更新数据表子窗体上的某些选定记录的值?


谢谢和欢呼。

Hello to all.

In what way can I update a certain selected records'' values on a datasheet subform using a command button which is located on the main form?

Thanks and cheers.

推荐答案

您可以使用其他文本字段在主窗体按钮的'OnClick事件中构造UPDATE查询在名为txtNewValue的主窗体上,如:


currentdb.execute(" Update tblX Set TextFieldA =''"& me.txtNewValue&"''where ID =" ;& me.subformname.form.ID)


或数字:


currentdb.execute(" Update tblX Set NumberFieldB ="& me.txtNewValue&" WHERE ID ="& me.subformname.form.ID)


" .subformname.form"需要引用子表单当前记录的唯一键。当然,您需要将名称更改为子表单的名称....

获取主意?


Nic; o)
You can construct an UPDATE query in the mainform buttons'' OnClick event, using an additional textfield on the mainform named txtNewValue, like:

currentdb.execute ("Update tblX Set TextFieldA=''" & me.txtNewValue & "'' where ID=" & me.subformname.form.ID)

or for a number:

currentdb.execute ("Update tblX Set NumberFieldB=" & me.txtNewValue & " WHERE ID=" & me.subformname.form.ID)

The ".subformname.form" is needed to refer to the unique key of the current record of the subform. Ofcourse you need to change the name to the name of your subform....
Getting the idea?

Nic;o)



您可以在主窗体按钮的'OnClick事件中使用名为txtNewValue的主窗体上的附加文本字段构建UPDATE查询,如:


currentdb.execute(" Update tblX Set TextFieldA =''"& me.txtNewValue&"''where ID ="& me.subformname.form.ID)


或一个数字:


currentdb.execute(" Update tblX Set NumberFieldB ="& me.txtNewValue&" WHERE ID ="& me.subformname.form.ID)


" .subformname.form"需要引用子表单当前记录的唯一键。当然,您需要将名称更改为子表单的名称....

获取主意?


Nic; o)
You can construct an UPDATE query in the mainform buttons'' OnClick event, using an additional textfield on the mainform named txtNewValue, like:

currentdb.execute ("Update tblX Set TextFieldA=''" & me.txtNewValue & "'' where ID=" & me.subformname.form.ID)

or for a number:

currentdb.execute ("Update tblX Set NumberFieldB=" & me.txtNewValue & " WHERE ID=" & me.subformname.form.ID)

The ".subformname.form" is needed to refer to the unique key of the current record of the subform. Ofcourse you need to change the name to the name of your subform....
Getting the idea?

Nic;o)



不,我在谈论几个记录选择。

当我在数据表子表单上使用鼠标进行选择时,我需要一个按钮才能更新选定的值。问题是,当我按下主窗体上的按钮时,焦点从选择和选择中消失。

Nope, I''m talking about several records selection.
When I make a selection using the mouse on the datasheet subform, I need a button to be able to update the selected values. Problem is, as I press button on the main form, the focus dissaperas from the selection and the selection drops.


你将需要子窗体的OnCurrent事件,其代码如下:


Private Sub Form_MouseUp(按钮为整数,Shift为整数,X为单,Y为单)


On Error Resume Next


Parent.txtSelLength = Me.SelHeight

Parent.txtSelstart = Me.SelTop


Dim rs As Recordset

Dim intI As Integer


设置rs = Me.RecordsetClone


rs.MoveFirst

intI = 1

而intI< Me.SelTop

intI = intI + 1

rs.MoveNext

Wend

''现在位于第一个


''初始结果字段

Parent.txtSelected =""


intI = 0


而intI< Me.SelHeight

Parent.txtSelected = Parent.txtSelected& " " &安培; rs!Field1

intI = intI + 1

rs.MoveNext

Wend


设置rs =没有什么


结束子


当您在主窗体上放置Parent.txt ...字段并将rs!field1更改为名称时你的关键字域,然后你会看到效果。 (确保你有一个DAO库的参考设置)


Nic; o)
You''ll need the subform''s OnCurrent event with code like:

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

On Error Resume Next

Parent.txtSelLength = Me.SelHeight
Parent.txtSelstart = Me.SelTop

Dim rs As Recordset
Dim intI As Integer

Set rs = Me.RecordsetClone

rs.MoveFirst
intI = 1
While intI < Me.SelTop
intI = intI + 1
rs.MoveNext
Wend
''now positioned on the first

''Init resultfield
Parent.txtSelected = ""

intI = 0

While intI < Me.SelHeight
Parent.txtSelected = Parent.txtSelected & " " & rs!Field1
intI = intI + 1
rs.MoveNext
Wend

Set rs = Nothing

End Sub

When you place the Parent.txt... fields on your mainform and change rs!field1 into the name of your keyfield, then you''ll see the effect. (Make sure you have a reference set to the DAO library)

Nic;o)


这篇关于如何使用seltop和selheight更新数据表子表单上的选定记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆