按顺序编号一个字段! [英] Sequentially numbering a field !

查看:75
本文介绍了按顺序编号一个字段!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


我有一个字段sub_tran_no在我的表格中连续查看。


当用户按下重新编号按钮时,我想:


1)保存当前记录指针位置

2)保存当前具有焦点的字段

3)转到记录集的顶部&开始重新编号

sub_tran_no字段值1,2,3,直到eof。

4)返回上一个记录号

5)将焦点设置到最后一个字段。

6)刷新表单以显示结果


我应该使用Recordset还是RecordsetClone来执行此操作。


任何人都可以请帮助一点Air-Code?


Thx&最好的Rgds,

Prakash。

Hi !

I have a field "sub_tran_no" in my form in continuous view.

When the user presses a button "Re-Number", I''d like to:

1) Save the current record pointer position
2) Save the current field which has focus
3) go to the top of the recordset & start re-numbering
the "sub_tran_no" field with the values 1,2,3, until eof.
4) go back to the previous record number
5) set focus to the last field.
6) Refresh the form to display the results

Should I do this using Recordset or RecordsetClone.

Could anyone please help with a little Air-Code ?

Thx & Best Rgds,
Prakash.

推荐答案

你说sub_tran_no是一个字段。我只想验证它是一个字段和

你有一个绑定的文本框,而不是它只是一个未绑定的文本框。如果

你使用记录集克隆工作,表单永远不会移动,

因此应该没有什么可以保存。如果你重新查询表单,你将会丢失书签,光标将返回第一条记录。如果需要

重新查询,您需要记住当前记录的唯一ID

字段的值,然后搜索回该记录。


Dim rst作为DAO.Recordset,lngNumber As Long

Set rst = Me.RecordsetClone

If Not(rst.BOF并且rst.EOF)那么

rst

.MoveFirst

lngNumber = 0

Do Until .EOF

lngNumber = lngNumber + 1

。编辑

![FieldName] = lngNumber

。更新

.MoveNext

循环

。关闭

结束

结束如果

设置rst = Nothing

Me.Refresh


刷新将获取已经在表格中的记录的新值

记录集。如果你有一个多用户数据库,它不会得到其他人可能添加的新记录

。当然,如果另一个用户已经添加了

记录,并且你要求获得这些记录,那么你的数字就不会再是连续的了。 br />

你是否需要记住你所处的位置并回到它:


Dim lngID As Long,strControl As String

lngID = Me.txtIDField

strControl = Me.ActiveControl.Name

''做什么导致光标移动

Me.Recordset.FindFirst" [IDField] =" &安培; lngID

Me.Controls(strControl).SetFocus


-

Wayne Morgan

MS访问MVP

" Prakash" < SI **** @ omantel.net.om>在消息中写道

news:11 ********************** @ g44g2000cwa.googlegr oups.com ...
You say sub_tran_no is a field. I just want to verify that it is a field and
that you have a bound textbox, not that it is just an unbound textbox. If
you do the work with the recordset clone, the form should never move,
therefore there should be nothing to save. If you requery the form, you will
lose the Bookmark and the cursor will return to the first record. If a
requery is necessary, you''ll need to remember the value of the unique ID
field for the current record and then do a search back to that record.

Dim rst As DAO.Recordset, lngNumber As Long
Set rst = Me.RecordsetClone
If Not (rst.BOF And rst.EOF) Then
With rst
.MoveFirst
lngNumber = 0
Do Until .EOF
lngNumber = lngNumber + 1
.Edit
![FieldName] = lngNumber
.Update
.MoveNext
Loop
.Close
End With
End If
Set rst = Nothing
Me.Refresh

Refresh will get the new values for records that are already in the form''s
recordset. It won''t get new records that may have been added by someone else
if you have a multi-user database. Of course, if another user has added
records and you requery to get those records, you''re numbers aren''t going to
be sequential any longer.

Should you need to remember where you''re at and move back to it:

Dim lngID As Long, strControl As String
lngID = Me.txtIDField
strControl = Me.ActiveControl.Name
''do what ever causes the cursor to move
Me.Recordset.FindFirst "[IDField]=" & lngID
Me.Controls(strControl).SetFocus

--
Wayne Morgan
MS Access MVP
"Prakash" <si****@omantel.net.om> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
嗨!

我有一个字段sub_tran_no在用户连续按下Re-Number按钮时,我想:> 1)保存当前记录指针位置
2)保存当前具有焦点的字段
3)转到记录集的顶部。开始重新编号
sub_tran_no字段值1,2,3,直到eof。
4)返回上一个记录号
5)将焦点设置到最后一个字段。
6)刷新表单进行显示结果

我应该使用Recordset还是RecordsetClone来实现这个目标。

任何人都可以请一点Air Code:

Thx&最好的Rgds,
Prakash。
Hi !

I have a field "sub_tran_no" in my form in continuous view.

When the user presses a button "Re-Number", I''d like to:

1) Save the current record pointer position
2) Save the current field which has focus
3) go to the top of the recordset & start re-numbering
the "sub_tran_no" field with the values 1,2,3, until eof.
4) go back to the previous record number
5) set focus to the last field.
6) Refresh the form to display the results

Should I do this using Recordset or RecordsetClone.

Could anyone please help with a little Air-Code ?

Thx & Best Rgds,
Prakash.



>嗨!


何! ;-)
> Hi !

Ho! ;-)
我有一个字段sub_tran_no在用户连续按下Re-Number按钮时,我想:> 1)保存当前记录指针位置


表的主键是什么?将其值存储在(a)变量中。

2)保存当前具有焦点的字段


dim focuscontrol as control

设置focuscontrol = screen.previouscontrol''因为用户点击

按钮< -focus,不要使用activecontrol

3)回到顶端记录集&开始重新编号
sub_tran_no字段值1,2,3,直到eof。


你是什么意思记录集的顶部?您设想的是什么顺序?


如果您在代码中创建sub_tran_no,我真诚地希望您这样做,那么

可能是重新编号的原因?啊,用户删除交易(

克服你的255限制)并尝试添加新的交易。这失败了因为

你已经在代码中加了254。如何测试

交易记录的数量,然后,而不是测试交易数量?

(双关语)

4)go回到之前的记录号码


with me.recordsetclone

.findfirst yourprimarykeyexpression''可以在我知道
$ b后立即帮助你$ b字段

me.bookmark = .bookmark

结束

5)将焦点设置为最后一个字段。


focuscontrol.setfocus''我们已经设置了以上

6)刷新表单以显示结果


呃,这是错误的方式。这将是第3步的一部分:me.requery

我应该使用Recordset还是RecordsetClone来执行此操作。
I have a field "sub_tran_no" in my form in continuous view.

When the user presses a button "Re-Number", I''d like to:

1) Save the current record pointer position
What is the primary key of the table? Store its value(s) in (a) variable(s).
2) Save the current field which has focus
dim focuscontrol as control
set focuscontrol = screen.previouscontrol''because user clicks
button<-focus, don''t use activecontrol
3) go to the top of the recordset & start re-numbering
the "sub_tran_no" field with the values 1,2,3, until eof.
What do you mean by "top of the recordset"? What order do you envision?

If you create sub_tran_no in code, which I sincerely hope you do, what
could be the reason to renumber? Ah, user deletes transactions (to
overcome your 255 limit) and tries to add new ones. That fails because
you''ve put 254 in the code. How about testing for the number of
transaction records, then, instead of testing the transaction number?
(pun intended)
4) go back to the previous record number
with me.recordsetclone
.findfirst yourprimarykeyexpression ''can help you as soon as I know the
field(s)
me.bookmark = .bookmark
end with
5) set focus to the last field.
focuscontrol.setfocus '' we''ve set that above
6) Refresh the form to display the results
Er, that''s the wrong way around. It would be part of step 3: me.requery
Should I do this using Recordset or RecordsetClone.




我会使用记录集,但我看不出真正的理由不使用

recordsetclone。让我们看看帮助是否对此有所了解...

为什么,不,如果你想要执行,b / b
表示即使是记录集克隆也是如此对表格记录的操作。


记录的顺序是什么?就是那个问题。我想现在,每个.recordsource的记录都是按照要求的顺序,而你想要重新编号,只是为了缩小序列中的间隙。

。必须

是一个数学术语,我不会用英语知道。


dim i as integer

i = 0''起始值

with me.recordsetclone

do to .eof

!sub_tran_no = i

i = i + 1

.movenext

循环

结束


可能正常工作。


-

Bas Cost Budde,荷兰
http://www.heuveltop.nl/BasCB/msac_index.html

对于人类回复,请用茶替换队列



I would have used a recordset, but I can''t see a real reason not to use
the recordsetclone. Let''s see if the Help sheds some light on this...
why, no, recordsetclone is even advised as the way to go if you want to
perform operations on the records in the form.

What is the order of the records? That is the question. I suppose for
now that the records per .recordsource are in the required order, and
that you want to renumber just to close gaps in the sequence. There must
be a mathematical term for that, which I don''t know in English.

dim i as integer
i=0 '' starting value
with me.recordsetclone
do until .eof
!sub_tran_no = i
i=i+1
.movenext
loop
end with

might just work.

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
For human replies, replace the queue with a tea


Bas是正确的ActiveControl,改为使用Screen.PreviousControl。


-

Wayne Morgan

MS Access MVP
Bas is correct about ActiveControl, use Screen.PreviousControl instead.

--
Wayne Morgan
MS Access MVP


这篇关于按顺序编号一个字段!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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