MS ACCESS 2003 - 有关将信息从未绑定表单传递到报告的问题

发布于 2024-08-17 11:42:16 字数 1610 浏览 8 评论 0原文

我使用类似下面的东西将信息从一个未绑定的表单传递到另一个(请原谅没有错误检查):

Sub Button_Click()
Dim db as DAO.database
Dim rs as DAO.recordset
Dim sql as string

docmd.openform "NextFormIamAbouttoUse"

sql = "SELECT * FROM tblMain WHERE MainID = " & Me.As_MainID & ";"

' usually debug here

set db = currentdb
set rs = db.openrecordset(sql)

if rs.eof then
   msgbox "oops message"
else
     rs.movefirst
          [Forms]![NextFormIamAbouttoUse].as_mainID = rs![MainID]
          [forms]![NextFormIamAbouttoUse].value1 = rs![value1]
          ' etc

     rs.close
     set db = nothing
     set rs = nothing
     sql = ""
 end if

 'error stuff
  end sub

好的,那么我也可以使用这种东西将信息从表单传输到报告?我使用了很多充满文本框的表单作为仪表板,其中文本框没有输入目的,而是显示快速信息。

用户浏览不同的表单以根据自己的喜好构建“类似仪表板”的表单,然后在某个时候想要打印。所以我想在每个点构建类似的(就提供的数据而言)报告,以便他们可以打印通过这些表格构建的信息页。

所以我尝试用报告来做到这一点:

Sub Button_Click()
Dim db as DAO.database
Dim rs as DAO.recordset
Dim sql as string

docmd.openreport "ReportTester", acViewPreview

sql = "SELECT * FROM tblMain WHERE MainID = " & Me.As_MainID & ";"

' usually debug here

set db = currentdb
set rs = db.openrecordset(sql)

if rs.eof then
   msgbox "oops message"
else
     rs.movefirst
          [reports]![ReportTester].as_mainID = rs![MainID]
          [reports]![ReportTester].value1 = rs![value1]
          ' etc

     rs.close
     set db = nothing
     set rs = nothing
     sql = ""
 end if

 'error stuff
  end sub

只是作为猜测,但没有成功。没有错误,或者任何东西。只是不会以这种方式显示任何信息。连身份证号码都不会传。

所以我认为在 AcViewPreview 中打开报告意味着我无法在事后向这些文本框添加信息,但我只是不确定。因此,非常感谢对此的任何建议。谢谢!

I use something like below to pass information from one unbound form to another (excuse the no error checking):

Sub Button_Click()
Dim db as DAO.database
Dim rs as DAO.recordset
Dim sql as string

docmd.openform "NextFormIamAbouttoUse"

sql = "SELECT * FROM tblMain WHERE MainID = " & Me.As_MainID & ";"

' usually debug here

set db = currentdb
set rs = db.openrecordset(sql)

if rs.eof then
   msgbox "oops message"
else
     rs.movefirst
          [Forms]![NextFormIamAbouttoUse].as_mainID = rs![MainID]
          [forms]![NextFormIamAbouttoUse].value1 = rs![value1]
          ' etc

     rs.close
     set db = nothing
     set rs = nothing
     sql = ""
 end if

 'error stuff
  end sub

ok so i can use this kind of thing for transferring information from forms to reports as well? see i use a lot of forms full of text boxes as dashboards, where the text boxes serve no entry purpose, rather display quick information rather.

user navigate through different forms to build the "dashboard-like" forms to their liking then at some point want to print. so i wanted to build look-a-like (in terms of the data offered) reports at each point so they can print the page of information they have built through these forms.

so i tried to do this with a report:

Sub Button_Click()
Dim db as DAO.database
Dim rs as DAO.recordset
Dim sql as string

docmd.openreport "ReportTester", acViewPreview

sql = "SELECT * FROM tblMain WHERE MainID = " & Me.As_MainID & ";"

' usually debug here

set db = currentdb
set rs = db.openrecordset(sql)

if rs.eof then
   msgbox "oops message"
else
     rs.movefirst
          [reports]![ReportTester].as_mainID = rs![MainID]
          [reports]![ReportTester].value1 = rs![value1]
          ' etc

     rs.close
     set db = nothing
     set rs = nothing
     sql = ""
 end if

 'error stuff
  end sub

just as a guess, and it didn't work. no errors, or anything. just will not display any information this way. won't even pass the ID number.

So I am thinking that opening the report in AcViewPreview means that I cannot add information to those text boxes after the fact, but I am jsut not certain. So any advice on this is much appreciated. thanks!

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

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

发布评论

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

评论(2

枫林﹌晚霞¤ 2024-08-24 11:42:16

你有几个选择。您可以创建一个查询,并将表单控件值传递到其中的值,从而创建一个包含 1 条记录的查询,您可以将其作为报告的基础。

每列将如下所示:数据:表单![MyForm]![MyControl]

或者您可以将表单中的控件直接绑定到报表控件。

如果您选择其中任一途径,则在打开报告时,您需要保持包含值的表单处于打开状态。不需要复杂的代码。

You have a few options. You can either create a query, and pass the form control values into the values there, thus creating a 1 record query, which you can base your report on.

Each Column will look like this: Data: Forms![MyForm]![MyControl]

Or you can just bind the controls from the form directly to the report controls.

You will need to leave the form open containing the values while the report is opened, if you opt for either of these routes. No complex code needed.

装迷糊 2024-08-24 11:42:16

我想我错过了一些东西。为什么不让报表的 Recordsource 与表单的 Recordsource 相同,然后在运行时过滤到 DoCmd.OpenReport 的WhereCondition 参数中的特定 MainID?然后您无需打开表单即可运行报告。

除非表单未绑定,或者具有动态计算成本高昂的字段,否则我根本看不到将报表绑定到表单有任何优势。

I think I'm missing something. Why wouldn't you just have the report's Recordsource be the same as the form's Recordsource, and then filter at runtime to a particular MainID in the DoCmd.OpenReport's WhereCondition argument? Then you can run the report without needing to have the form open.

Unless the form is unbound, or has fields that are expensive to calculate on the fly, I can't see any advantage to binding the report to the form at all.

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