通过在表格上查找报告名称来打开报告 [英] Open Report by looking for the Report name on a table

查看:51
本文介绍了通过在表格上查找报告名称来打开报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有不同版本的报告用于不同的月份。

例如,我使用报告版本1截至9月,但我们有

10月报告的一些设计更改,所以我创建了报告

版本2.我想要一个相同的命令按钮打开拨款

特定月份的版本报告。


我创建一个包含以下字段的表:Month,ReportID,

ReportToOpen(这是确切的报告名称)。在表单上,​​我输入了

字段Month,以及一个用于点击&的命令按钮。打开报告。我

创建VB代码以从表中查找报告名称,并在表单上输入一个月后单击按钮时打开

特定报告。

我需要一份正确的报告才能打开。


有人可以帮我吗?非常感谢您的帮助!!


这是我的代码,但有错误(参数太少。预期2.)。我不知道这是不是正确的做法,但这是'b
$ b的逻辑:


Dim stDocName As String

Dim mth As Date

Dim db As DAO.Database

Dim rs As DAO.Recordset

Dim strSQL As String

设置db = CurrentDb()

mth =格式(Me.CurrentMonth," m / dd / yyyy")


''** stDocName = Tables![ReportOpenTable]![ReportToOpen]

strSQL =" SELECT ReportToOpen FROM ReportOpenTable WHERE ReportID =

RSD4和月= mth


设置rs = db.OpenRecordset(strSQL)

stDocName = strSQL

''* * stDocName =" RSD3-Territory of Territory = TotalV2"


''**如果DLookup([Position]"," ReportOpenTable",[ReportID] =''RSD4''")

=" RSD" ''然后


DoCmd.OpenReport stDocName,acPreview


''**否则

'' ** MsgBox(oop)


''** DoCmd.OpenReport" RSD3-Territory of Sales = Total",acPreview

'' **结束如果

Hello all,
I have different version of reports which used for different months.
For example, I am using report version 1 up to September, but we have
some design changes on the report for October, so I created report
version 2. I want a same Command Button to open the appropriated
version report for the specific month.

I create a table with the following Fields: Month, ReportID,
ReportToOpen (this is the exact report name). On a form, I have input
field "Month", and a Command Button to click & open the report. I
create VB code to look for the Report name from the table and open the
specific report when click the button after input a month on the form.
I need a right report to open.

Could someone help me on this? Your help is greatly appreciated!!

Here is my code, but with error ("Too few parameters. Expected 2.). I
am not sure if this is the right way to do it, but this''s the logic i
have:

Dim stDocName As String
Dim mth As Date
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb()
mth = Format(Me.CurrentMonth, "m/dd/yyyy")

''**stDocName = Tables![ReportOpenTable]![ReportToOpen]
strSQL = "SELECT ReportToOpen FROM ReportOpenTable WHERE ReportID =
RSD4 and month= mth"

Set rs = db.OpenRecordset(strSQL)
stDocName = strSQL
''**stDocName = "RSD3-Sales by Territory=TotalV2"

''**If DLookup("[Position]", "ReportOpenTable", "[ReportID] = ''RSD4''")
= "RSD" ''**Then

DoCmd.OpenReport stDocName, acPreview

''**Else
''**MsgBox ("oop")

''**DoCmd.OpenReport "RSD3-Sales by Territory=Total", acPreview
''**End If

推荐答案

Orchid写道:
Orchid wrote:

你好所有,

我有不同版本的报告用于不同月份。

例如,我使用报告版本1截至9月,但我们有

10月报告中的一些设计更改,所以我创建了报告

版本2.我想要一个相同的命令按钮来打开特定的

版本报告月份。


我创建一个包含以下字段的表:Month,ReportID,

ReportToOpen(这是确切的报告名称)。在表单上,​​我输入了

字段Month,以及一个用于点击&的命令按钮。打开报告。我

创建VB代码以从表中查找报告名称,并在表单上输入一个月后单击按钮时打开

特定报告。

我需要一份正确的报告才能打开。


有人可以帮我吗?非常感谢您的帮助!!


这是我的代码,但有错误(参数太少。预期2.)。我不确定这是否是正确的方法,但这是'b
$ b的逻辑:
Hello all,
I have different version of reports which used for different months.
For example, I am using report version 1 up to September, but we have
some design changes on the report for October, so I created report
version 2. I want a same Command Button to open the appropriated
version report for the specific month.

I create a table with the following Fields: Month, ReportID,
ReportToOpen (this is the exact report name). On a form, I have input
field "Month", and a Command Button to click & open the report. I
create VB code to look for the Report name from the table and open the
specific report when click the button after input a month on the form.
I need a right report to open.

Could someone help me on this? Your help is greatly appreciated!!

Here is my code, but with error ("Too few parameters. Expected 2.). I
am not sure if this is the right way to do it, but this''s the logic i
have:



如果IsNull(Me.CurrentMonth)那么

''如果当前月份为空则无需处理。

If IsNull(Me.CurrentMonth) then
''no need to process if current month is empty.


Dim stDocName As String

Dim mth As Date
Dim stDocName As String
Dim mth As Date



''Dim mth As Date needed needed

''Dim mth As Date unneeded


Dim db作为DAO.Database

Dim rs作为DAO.Recordset

Dim strSQL As String


Set db = CurrentDb()

mth =格式(Me.CurrentMonth," m / dd / yyyy")
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb()
mth = Format(Me.CurrentMonth, "m/dd/yyyy")



''mth =格式(Me.CurrentMonth,m / dd / yyyy)不需要


如果mth< 10然后

strDocName =" Report1"

Else

strDocName =" Report2"

Endif


DoCmd.OpenReport strDocName,acPreview


''其余的代码是不需要的,因为我可以看出

''mth = Format(Me.CurrentMonth, "m/dd/yyyy") unneeded

If mth < 10 then
strDocName = "Report1"
Else
strDocName = "Report2"
Endif

DoCmd.OpenReport strDocName, acPreview

''the rest of your code is unneeded near as I can make out


>

''** stDocName = Tables![ReportOpenTable]![ReportToOpen]

strSQL =" SELECT ReportToOpen FROM ReportOpenTable WHERE ReportID =

RSD4和month = mth"


设置rs = db.OpenRecordset(strSQL)

stDocName = strSQL

''** stDocName =" RSD3-按地区销售= TotalV2"


''**如果DLookup([Position], ReportOpenTable,[ReportID] =''RSD4''")

=" RSD" ''然后


DoCmd.OpenReport stDocName,acPreview


''**否则

'' ** MsgBox(oop)


''** DoCmd.OpenReport" RSD3-Territory of Sales = Total",acPreview

'' **结束如果
>
''**stDocName = Tables![ReportOpenTable]![ReportToOpen]
strSQL = "SELECT ReportToOpen FROM ReportOpenTable WHERE ReportID =
RSD4 and month= mth"

Set rs = db.OpenRecordset(strSQL)
stDocName = strSQL
''**stDocName = "RSD3-Sales by Territory=TotalV2"

''**If DLookup("[Position]", "ReportOpenTable", "[ReportID] = ''RSD4''")
= "RSD" ''**Then

DoCmd.OpenReport stDocName, acPreview

''**Else
''**MsgBox ("oop")

''**DoCmd.OpenReport "RSD3-Sales by Territory=Total", acPreview
''**End If


错误来自您的陈述

strSQL =" SELECT ReportToOpen FROM ReportOpenTable WHERE ReportID =

RSD4和月= mth"


它应该是

strSQL =" SELECT ReportToOpen FROM ReportOpenTable WHERE ReportID =

''RSD4''和月份=" &安培; mth


希望有所帮助!


Orchid写道:
The error comes from your statement
strSQL = "SELECT ReportToOpen FROM ReportOpenTable WHERE ReportID =
RSD4 and month= mth"

It should be
strSQL = "SELECT ReportToOpen FROM ReportOpenTable WHERE ReportID =
''RSD4'' and month = " & mth

Hope that helps!

Orchid wrote:

你好所有,

我有不同版本的报告用于不同月份。

例如,我使用报告版本1截至9月,但我们有

10月报告中的一些设计更改,所以我创建了报告

版本2.我想要一个相同的命令按钮来打开特定的

版本报告月份。


我创建一个包含以下字段的表:Month,ReportID,

ReportToOpen(这是确切的报告名称)。在表单上,​​我输入了

字段Month,以及一个用于点击&的命令按钮。打开报告。我

创建VB代码以从表中查找报告名称,并在表单上输入一个月后单击按钮时打开

特定报告。

我需要一份正确的报告才能打开。


有人可以帮我吗?非常感谢您的帮助!!


这是我的代码,但有错误(参数太少。预期2.)。我不知道这是不是正确的做法,但这是'b
$ b的逻辑:


Dim stDocName As String

Dim mth As Date

Dim db As DAO.Database

Dim rs As DAO.Recordset

Dim strSQL As String


设置db = CurrentDb()

mth =格式(Me.CurrentMonth," m / dd / yyyy" )


'' ** stDocName =表[ReportOpenTable] [ReportToOpen]

STRSQL = QUOT;!SELECT ReportToOpen FROM ReportOpenTable WHERE ReportID =

RSD4和月= mth"


设置rs = db.OpenRecordset(strSQL)

stDocName = strSQL

''** stDocName =" RSD3-Territory的销售额= TotalV2"


''**如果DLookup([Position]",ReportOpenTable", ; [ReportID] =''RSD4''")

=" RSD" ''然后


DoCmd.OpenReport stDocName,acPreview


''**否则

'' ** MsgBox(oop)


''** DoCmd.OpenReport" RSD3-Territory of Sales = Total",acPreview

'' **结束如果
Hello all,
I have different version of reports which used for different months.
For example, I am using report version 1 up to September, but we have
some design changes on the report for October, so I created report
version 2. I want a same Command Button to open the appropriated
version report for the specific month.

I create a table with the following Fields: Month, ReportID,
ReportToOpen (this is the exact report name). On a form, I have input
field "Month", and a Command Button to click & open the report. I
create VB code to look for the Report name from the table and open the
specific report when click the button after input a month on the form.
I need a right report to open.

Could someone help me on this? Your help is greatly appreciated!!

Here is my code, but with error ("Too few parameters. Expected 2.). I
am not sure if this is the right way to do it, but this''s the logic i
have:

Dim stDocName As String
Dim mth As Date
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb()
mth = Format(Me.CurrentMonth, "m/dd/yyyy")

''**stDocName = Tables![ReportOpenTable]![ReportToOpen]
strSQL = "SELECT ReportToOpen FROM ReportOpenTable WHERE ReportID =
RSD4 and month= mth"

Set rs = db.OpenRecordset(strSQL)
stDocName = strSQL
''**stDocName = "RSD3-Sales by Territory=TotalV2"

''**If DLookup("[Position]", "ReportOpenTable", "[ReportID] = ''RSD4''")
= "RSD" ''**Then

DoCmd.OpenReport stDocName, acPreview

''**Else
''**MsgBox ("oop")

''**DoCmd.OpenReport "RSD3-Sales by Territory=Total", acPreview
''**End If


感谢您的回复!

我希望从表中检索报告名称而不是硬

编码,因为我将为报告提供另一个版本,比同一个按钮打开的2个版本报告更多

。因此,为了使

更容易,我有一张表来记录要为

月打开的报告名称。我想匹配表中的月份然后打开报告

来自表格的名称。

您还有其他建议吗?提前致谢!


salad写道:
Thanks for your reply!
I want the report name to be retrieved from a table instead of hard
coded, because I will have another version for the report which is more
than 2 version reports opened by the same button. Therefore, to make
it easier, I have a table to record which report name to open for the
month. I want to match the month from the table then open the report
name from table.
Do you have other suggestions? Thanks in advance!

salad wrote:

Orchid写道:
Orchid wrote:

大家好,

我有不同版本的报告用于不同月份。

例如,我使用报告版本1到9月,但我们对于10月份的报告有一些设计更改,所以我创建了报告

版本2.我想要一个相同的命令按钮来打开拨款

特定月份的版本报告。


我创建一个包含以下字段的表:Month,ReportID,

ReportToOpen(这是确切的报告名称) 。在表单上,​​我输入了

字段Month,以及一个用于点击&的命令按钮。打开报告。我

创建VB代码以从表中查找报告名称,并在表单上输入一个月后单击按钮时打开

特定报告。

我需要一份正确的报告才能打开。


有人可以帮我吗?非常感谢您的帮助!!


这是我的代码,但有错误(参数太少。预期2.)。我不知道这是不是正确的做法,但这是'b
$ b
Hello all,
I have different version of reports which used for different months.
For example, I am using report version 1 up to September, but we have
some design changes on the report for October, so I created report
version 2. I want a same Command Button to open the appropriated
version report for the specific month.

I create a table with the following Fields: Month, ReportID,
ReportToOpen (this is the exact report name). On a form, I have input
field "Month", and a Command Button to click & open the report. I
create VB code to look for the Report name from the table and open the
specific report when click the button after input a month on the form.
I need a right report to open.

Could someone help me on this? Your help is greatly appreciated!!

Here is my code, but with error ("Too few parameters. Expected 2.). I
am not sure if this is the right way to do it, but this''s the logic i
have:



如果IsNull(Me.CurrentMonth)那么

''如果当前月份为空则无需处理。


If IsNull(Me.CurrentMonth) then
''no need to process if current month is empty.


Dim stDocName As String

Dim mth As Date
Dim stDocName As String
Dim mth As Date



''Dim mth As Date needed needed


''Dim mth As Date unneeded


Dim db作为DAO.Database

Dim rs作为DAO.Recordset

Dim strSQL As String

设置db = CurrentDb( )

mth =格式(Me.CurrentMonth," m / dd / yyyy")
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb()
mth = Format(Me.CurrentMonth, "m/dd/yyyy")



''th =格式化(Me。 CurrentMonth,m / dd / yyyy)不需要


如果mth< 10然后

strDocName =" Report1"

Else

strDocName =" Report2"

Endif


DoCmd.OpenReport strDocName,acPreview


''其余的代码是不需要的,因为我可以看出


''mth = Format(Me.CurrentMonth, "m/dd/yyyy") unneeded

If mth < 10 then
strDocName = "Report1"
Else
strDocName = "Report2"
Endif

DoCmd.OpenReport strDocName, acPreview

''the rest of your code is unneeded near as I can make out



'' ** stDocName =表[ReportOpenTable] [ReportToOpen]

STRSQL = QUOT;!SELECT ReportToOpen FROM ReportOpenTable WHERE ReportID =

RSD4和月= mth"


设置rs = db.OpenRecordset(strSQL)

stDocName = strSQL

''** stDocName =" RSD3-Territory的销售额= TotalV2"


''**如果DLookup([Position]",ReportOpenTable", ; [ReportID] =''RSD4''")

=" RSD" ''然后


DoCmd.OpenReport stDocName,acPreview


''**否则

'' ** MsgBox(oop)


''** DoCmd.OpenReport" RSD3-Territory of Sales = Total",acPreview

'' **结束如果

''**stDocName = Tables![ReportOpenTable]![ReportToOpen]
strSQL = "SELECT ReportToOpen FROM ReportOpenTable WHERE ReportID =
RSD4 and month= mth"

Set rs = db.OpenRecordset(strSQL)
stDocName = strSQL
''**stDocName = "RSD3-Sales by Territory=TotalV2"

''**If DLookup("[Position]", "ReportOpenTable", "[ReportID] = ''RSD4''")
= "RSD" ''**Then

DoCmd.OpenReport stDocName, acPreview

''**Else
''**MsgBox ("oop")

''**DoCmd.OpenReport "RSD3-Sales by Territory=Total", acPreview
''**End If


这篇关于通过在表格上查找报告名称来打开报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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