如何获得VBA(或表达式)中的子表单记录号? [英] How to get at sub-form record number in VBA (or an expresion)?

查看:77
本文介绍了如何获得VBA(或表达式)中的子表单记录号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用子表单的记录号,无论如何在VB(Access 2003)中可以使用

吗?


我想使用子表单记录号作为主键的* part *

表示其数据显示在子表单上的表。主键的另一部分

是用于连接到主表的列。


例如我有一个带有主键TableA.Column1的TableA(主表)。

子表单中显示的TableB有一个主键由

Column1组成它连接到TableA.Column1和一个数字TableB.Column2

我总是想从1开始并按顺序编号。


如果我能得到子表单行号我可以简单地设置

TableB.Column2到该值。

任何其他方法都可以获得相同的结果!
< br $> b $ b -

Chris Green

解决方案

us **** @ isbd.co.uk 新闻中写道:442ef99d.0@entanet:

我希望能够使用子表单的记录号,无论如何它们在VB(Access 2003)中都可用吗?

我想使用子表单记录号作为表格的主要
键的*部分*,其数据显示在子表单上。主键的其他部分是用于加入
主表的列。

例如我有TableA(主表)和主键
TableA.Column1。在子表单中显示的表B有一个由其Column1连接到TableA.Column1
的主键和一个数字TableB.Column2,我总是希望从1开始并且
按顺序编号。

如果我可以得到子表格行号,我可以简单地将TableB.Column2设置为该值。

任何其他方式实现相同结果将是受欢迎的!




没有固定记录号这样的东西,因为

的顺序记录取决于在

表格的记录来源的SORT ORDER上。


听起来你想要的是一个行号(就像你可能在
中一样)
发票)这样你就可以保持行的顺序,因为它们是最初输入的
。在这种情况下,您只需在子窗体中显示

的记录集上使用DCount()+ 1来填充您的

行号字段。当然,如果一行被删除,那么

可能会导致重复,所以你可能会改为选择DMax()+ 1.


-

David W. Fenton http://www.dfenton.com/

usenet at dfenton dot com http://www.dfenton。 com / DFA /


David W. Fenton< XX ******* @ dfenton.com.invalid>写道:

us****@isbd.co.uk 在新闻中写道:442ef99d .0 @ entanet:

我希望能够使用子表单的记录号,它们在VB(Access 2003)中是否可用?

我想将子表格记录号用作主要表格的*部分*,表格的数据显示在子表格上。主键的其他部分是用于加入
主表的列。

例如我有TableA(主表)和主键
TableA.Column1。在子表单中显示的表B有一个由其Column1连接到TableA.Column1
的主键和一个数字TableB.Column2,我总是希望从1开始并且
按顺序编号。

如果我可以得到子表格行号,我可以简单地将TableB.Column2设置为该值。

任何其他方式实现相同结果将是受欢迎的!
没有固定的记录号码,因为记录的顺序取决于
表格的记录源的排序。 / blockquote>

在某种程度上是真的,但我想要的是出现在记录

选择器中的数字。在子表格的底部。这与我想要的子表单中的记录完全相关,因此访问

确实在其中有这些记录号。 (或者至少它是

可以生成它们)

听起来你想要的是一个行号(就像你可能在发票中那样)以便你可以保持最初输入的线条顺序。在这种情况下,您只需在子窗体中显示的记录集上使用DCount()+ 1来填充
行号字段。当然,如果一行被删除,那可能会导致重复,所以你可能会选择DMax()+ 1.



是的,好的,那就是我想要的是,我遇到的问题是当你在子表单中输入行时,如何
生成值。这不是
(通常)已填充的子表单,当它第一次出现时它只是

中有一条新记录行。我想将子表单中

''行号'列的值设置为行号,因为我添加了新的

行。我不认为将它设置为DCount()+ 1会做我想要的

,因为我输入数据。


我会尝试一下虽然。


-

Chris Green


us **** @ isbd.co.uk 写道:

David W. Fenton< XX *** ****@dfenton.com.invalid>写道:

us****@isbd.co.uk 在新闻中写道:442ef99d .0 @ entanet:

我希望能够使用子表单的记录号,它们在VB(Access 2003)中是否可用?

我想将子表格记录号用作主要表格的*部分*,表格的数据显示在子表格上。主键的其他部分是用于加入
主表的列。

例如我有TableA(主表)和主键
TableA.Column1。在子表单中显示的表B有一个由其Column1连接到TableA.Column1
的主键和一个数字TableB.Column2,我总是希望从1开始并且
按顺序编号。

如果我可以得到子表格行号,我可以简单地将TableB.Column2设置为该值。

任何其他方式实现相同结果将是受欢迎的!



没有固定记录号这样的东西,因为记录的顺序取决于记录源的排序顺序
表格。


在某种程度上是真的,但我想要的是记录
选择器中出现的数字。在子表格的底部。这与我想要的子表单中的记录完全有关系,因此Access确实在其中有这些记录号。 (或者至少它可以生成它们)

听起来像你想要的是一个行号(就像你可能在发票中那样)以便你可以保持最初输入的线条顺序。在这种情况下,您只需在子窗体中显示的记录集上使用DCount()+ 1来填充
行号字段。当然,如果一行被删除,那可能会导致重复,所以你可能会选择DMax()+ 1.


是的,好的,这正是我想要的,我遇到的问题是当你在子表单中输入行时如何生成值。这不是(通常)已经填充的子表单,当它第一次出现时它只有一个新记录行。我想在子表单中将
''行号'列的值设置为行号,因为我添加了新的
行。当我输入数据时,我不认为将它设置为DCount()+ 1会做我想要的事情。

我会尝试它。



不,我无论如何也无法使它工作。


我看不到如何编写DCoount()表达式以获得我想要的东西。


如果我这样说: -


= DCount([Column1],[TableB] )


我只是得到TableB中的总行数,这不是我想要的b $ b。


我无法看到如何为DCount编写第三个参数,以便

仅计算子表单中到目前为止的记录。它必须是

类似于: -


= DCount(" [Column1]"," [TableB]",[ Column1] =表格![FormA]![Column1]")


....但这只是给了我#Error。


-

Chris Green


I want to be able to use the record numbers of a sub-form, are they
available anyhow in VB (Access 2003)?

I want to use the sub-form record number as *part* of the primary key
for the table whose data is displayed on the sub-form. The other part
of the primary key is the column used to join to the master table.

E.g. I have TableA (the master table) with a primary key TableA.Column1.
TableB which is shown in the sub-form has a primary key made up of its
Column1 which joins to TableA.Column1 and a number TableB.Column2 which
I always want to start at 1 and be numbered sequentially.

If I can get at the sub-form row number I can simply set
TableB.Column2 to that value.
Any other way of achieving the same result would be welcome!

--
Chris Green

解决方案

us****@isbd.co.uk wrote in news:442ef99d.0@entanet:

I want to be able to use the record numbers of a sub-form, are
they available anyhow in VB (Access 2003)?

I want to use the sub-form record number as *part* of the primary
key for the table whose data is displayed on the sub-form. The
other part of the primary key is the column used to join to the
master table.

E.g. I have TableA (the master table) with a primary key
TableA.Column1. TableB which is shown in the sub-form has a
primary key made up of its Column1 which joins to TableA.Column1
and a number TableB.Column2 which I always want to start at 1 and
be numbered sequentially.

If I can get at the sub-form row number I can simply set
TableB.Column2 to that value.

Any other way of achieving the same result would be welcome!



There is no such thing as a fixed record number because the order of
the records depends on the SORT ORDER of the recordsource of the
form.

Sounds like what you want is a line number (like you might have in
an invoice) so that you can maintain the order of the lines as they
were originally entered. In that case, you would just populate your
line number field by using DCount() + 1 on the set of records that
are shown in the subform. Of course, if a line gets deleted, that
could cause duplicates, so you might instead choose DMax() + 1.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/


David W. Fenton <XX*******@dfenton.com.invalid> wrote:

us****@isbd.co.uk wrote in news:442ef99d.0@entanet:

I want to be able to use the record numbers of a sub-form, are
they available anyhow in VB (Access 2003)?

I want to use the sub-form record number as *part* of the primary
key for the table whose data is displayed on the sub-form. The
other part of the primary key is the column used to join to the
master table.

E.g. I have TableA (the master table) with a primary key
TableA.Column1. TableB which is shown in the sub-form has a
primary key made up of its Column1 which joins to TableA.Column1
and a number TableB.Column2 which I always want to start at 1 and
be numbered sequentially.

If I can get at the sub-form row number I can simply set
TableB.Column2 to that value.

Any other way of achieving the same result would be welcome!
There is no such thing as a fixed record number because the order of
the records depends on the SORT ORDER of the recordsource of the
form.


True in a way, but what I want is the number that appears in the "Record
Selector" at the bottom of the sub-form. That has exactly the
relationship with the records in the sub-form that I want so Access
does have these ''record numbers'' inside it somewhere. (Or at least it
can generate them)
Sounds like what you want is a line number (like you might have in
an invoice) so that you can maintain the order of the lines as they
were originally entered. In that case, you would just populate your
line number field by using DCount() + 1 on the set of records that
are shown in the subform. Of course, if a line gets deleted, that
could cause duplicates, so you might instead choose DMax() + 1.


Yes, OK, that''s exactly what I want, the problem I have is how to
generate the value as you enter lines into the sub-form. This isn''t
(usually) an already populated sub-form, when it first appears it just
has the one ''new record'' line in it. I want to set the value of the
''line number'' column in the sub-form to the line numbers as I add new
lines. I don''t think setting it to DCount() + 1 will do what I want
as I enter data.

I''ll try it though.

--
Chris Green


us****@isbd.co.uk wrote:

David W. Fenton <XX*******@dfenton.com.invalid> wrote:

us****@isbd.co.uk wrote in news:442ef99d.0@entanet:

I want to be able to use the record numbers of a sub-form, are
they available anyhow in VB (Access 2003)?

I want to use the sub-form record number as *part* of the primary
key for the table whose data is displayed on the sub-form. The
other part of the primary key is the column used to join to the
master table.

E.g. I have TableA (the master table) with a primary key
TableA.Column1. TableB which is shown in the sub-form has a
primary key made up of its Column1 which joins to TableA.Column1
and a number TableB.Column2 which I always want to start at 1 and
be numbered sequentially.

If I can get at the sub-form row number I can simply set
TableB.Column2 to that value.

Any other way of achieving the same result would be welcome!



There is no such thing as a fixed record number because the order of
the records depends on the SORT ORDER of the recordsource of the
form.


True in a way, but what I want is the number that appears in the "Record
Selector" at the bottom of the sub-form. That has exactly the
relationship with the records in the sub-form that I want so Access
does have these ''record numbers'' inside it somewhere. (Or at least it
can generate them)

Sounds like what you want is a line number (like you might have in
an invoice) so that you can maintain the order of the lines as they
were originally entered. In that case, you would just populate your
line number field by using DCount() + 1 on the set of records that
are shown in the subform. Of course, if a line gets deleted, that
could cause duplicates, so you might instead choose DMax() + 1.


Yes, OK, that''s exactly what I want, the problem I have is how to
generate the value as you enter lines into the sub-form. This isn''t
(usually) an already populated sub-form, when it first appears it just
has the one ''new record'' line in it. I want to set the value of the
''line number'' column in the sub-form to the line numbers as I add new
lines. I don''t think setting it to DCount() + 1 will do what I want
as I enter data.

I''ll try it though.


No, well I can''t make it work anyway.

I can''t see how to write the DCoount() expression to get what I want.

If I put something like:-

=DCount("[Column1]", "[TableB]")

I simply get the total number of rows in TableB which is not what I
want at all.

I can''t see how to write the third parameter for DCount so that it
only counts the records so far in the sub-form. It needs to be
something like:-

=DCount("[Column1]", "[TableB]", "[Column1]=Forms![FormA]![Column1]")

.... but this just gives me #Error.

--
Chris Green


这篇关于如何获得VBA(或表达式)中的子表单记录号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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