选择表单的特定记录

发布于 2024-08-12 07:13:56 字数 370 浏览 7 评论 0原文

在这个表单上,我创建了一个网格,几乎看起来像一个条形图,其中有按月堆叠的小“单元格”。每个“单元格”都是方形子表单,我创建了用作子表单的小方形表单。

所以我想知道的是,运行选择查询并且仅处理该查询中的特定记录的代码(VB)是什么?例如,这些像“单元格”一样的小表单中的每一个都会成为子表单,代表一个组织,如果我运行第 N 个查询,我会通过任何方式获得第 10 个顶级商店......所以我们的想法是使用每个小表格代表该查询中的每条记录。因此,对于第一个单元格,我想运行 SELECT 查询,获取结果,并仅处理第一条记录。然后在第二个表单上运行完全相同的查询,并仅处理第二条记录,依此类推!

我想这有点奇怪,但它会给他们他们想要的东西,我唯一不确定的部分是“准确定义我想在 VBA 中使用的记录”

On this form, I create a grid, almost looks like a bar chart with little "cells" stacked by month. Each of these "cells" are square sub forms, and I create the little square forms that I use as the sub forms.

So what I wanted to know is, what is the code (VB) for running a select query, and only working with specific records within that query? For example, each one of these little "cell" like forms that become the sub-forms, represent a organization, and if I run a top Nth query I get the 10 Top store by whatever....so the idea is to use each little form as a representative of each record from that query. So for the first cell I want to run the SELECT query, get the results, and work only with the first record. Then on the second form, run the exact same query, and work only with the second record, and so on!

Its a little weird I suppose, but it will give them exactly what they want, and the only part I am not sure about, is the "defining exactly which record I want to use in the VBA"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青朷 2024-08-19 07:13:56

您可以更改每个子表单的 SQL 来读取:

SELECT TOP 1 ID, F1, F2 From Table

SELECT TOP 2 From Table WHERE ID NOT IN (SELECT TOP 1 ID From Table)

SELECT TOP 3 From Table WHERE ID NOT IN (SELECT TOP 2 ID From Table)

<...>

SELECT TOP 10 From Table WHERE ID NOT IN (SELECT TOP 9 ID From Table)

或者,看到您已经有了一个有点奇怪的设置,您可以使用记录集将每个 ID 写入 10 个隐藏文本框控件之一,并使用每个文本框作为链接主字段,ID 作为子表单的链接子字段。

链接主字段和链接子字段是子表单控件的属性,而不是所包含的表单的属性。

替代文本 http://ltd.remou.com/linkchildlinkmaster.png

You could change the SQL for each sub form to read:

SELECT TOP 1 ID, F1, F2 From Table

SELECT TOP 2 From Table WHERE ID NOT IN (SELECT TOP 1 ID From Table)

SELECT TOP 3 From Table WHERE ID NOT IN (SELECT TOP 2 ID From Table)

<...>

SELECT TOP 10 From Table WHERE ID NOT IN (SELECT TOP 9 ID From Table)

Or, seeing you already have a somewhat odd set-up, you can write each ID to one of 10 hidden textbox controls using a recordset, and use each of these textboxes as the link master field with ID as the link child field for the subforms.

Link Master Field and Link Child Field are properties of the subform control, not the form contained.

alt text http://ltd.remou.com/linkchildlinkmaster.png

醉生梦死 2024-08-19 07:13:56

如果我正确理解你的请求,你可以做这样的事情。

表结构

ID Autonumber,
Col1 Text

VBCode

Private Sub Command0_Click()
Dim rec As Recordset
Dim id As Integer

    Set rec = CurrentDb.OpenRecordset("SELECT TOP 10 * FROM Table1")

    While Not rec.EOF
        id = rec.Fields("ID")
        rec.MoveNext
    Wend
End Sub

If i understand your request correctly yuo can do something like this.

Table Structure

ID Autonumber,
Col1 Text

VBCode

Private Sub Command0_Click()
Dim rec As Recordset
Dim id As Integer

    Set rec = CurrentDb.OpenRecordset("SELECT TOP 10 * FROM Table1")

    While Not rec.EOF
        id = rec.Fields("ID")
        rec.MoveNext
    Wend
End Sub
带上头具痛哭 2024-08-19 07:13:56

您将 SQL 语句视为伪表的定义,即可以像操作表一样操作的一组记录 (RecordSet)。

Dim cnn As ADODB.Connection
Dim pseudoTable As ADODB.Recordset
Dim strSQL As String

    Set cnn = CurrentProject.Connection
    Set pseudoTable = New ADODB.Recordset

    strSQL = "SELECT Title FROM realTable where realID < 1000;"
    pseudoTable.Open strSQL, cnn, adOpenStatic, adLockOptimistic
    If Not pseudoTable.BOF And Not pseudoTable.EOF Then
        pseudoTable.MoveFirst
        Do Until pseudoTable.EOF
            ' do something with the table
            pseudoTable.MoveNext
        Loop

上面的代码应该会给你一个好的开始。

You treat the SQL statement as the definition of a pseudoTable, i.e. a set of records (RecordSet) that you can manipulate as if it was a table.

Dim cnn As ADODB.Connection
Dim pseudoTable As ADODB.Recordset
Dim strSQL As String

    Set cnn = CurrentProject.Connection
    Set pseudoTable = New ADODB.Recordset

    strSQL = "SELECT Title FROM realTable where realID < 1000;"
    pseudoTable.Open strSQL, cnn, adOpenStatic, adLockOptimistic
    If Not pseudoTable.BOF And Not pseudoTable.EOF Then
        pseudoTable.MoveFirst
        Do Until pseudoTable.EOF
            ' do something with the table
            pseudoTable.MoveNext
        Loop

The above code should give you a good start.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文