在访问报告中为“分组依据"字段添加别名 [英] Have an alias for a 'grouped by' field in Access Report
问题描述
我想知道是否有任何方法可以将条件别名应用于用于将访问报告中的结果分组的文本框字段.
I was wondering if there is any way to apply a conditional alias to a text box field which is being used to group results in an Access Report.
为帮助解释,我提供了报告设计视图的图像. 区域标题中的区域"框按前7个字符进行分组.
To help explain, I have provided an image of the design view of my report. The 'Region' box in the Region Header is being grouped by the first 7 characters.
我有维克-墨尔本中央",维克-墨尔本南"和维克-墨尔本东"等地区.它们按7个字符进行分组,以确保按我的意愿将所有以"Vic-M"开头的区域组合在一起.但是,然后我希望区域标题"中的区域"字段显示墨尔本".当前显示的是维克-墨尔本中央",因为它是订单中的第一个值.
I have regions such as "Vic - Melbourne Central", "Vic - Melbourne South", and "Vic - Melbourne East". They are being grouped by 7 characters as that ensures all Regions starting with "Vic - M" are grouped together as I want. However I then want the Region field in the Region Header to display "Melbourne". It currently displays "Vic - Melbourne Central" as it is the first value in order.
这可能吗? 我可以在报告中打开一些VBA代码,以搜索Region ="Vic-Melbourne Central"并输出"Melbourne"吗?
Is this possible? Could I have some VBA code that on report open it searches for Region = "Vic - Melbourne Central" and outputs "Melbourne"?
推荐答案
必须对报表的查询进行任何更改.您可以让Function拆分名称,然后在查询中简单地调用它:
Any changes will have to be made to the report's query. You can have a Function split the name and simply call it in your query:
Public Function RegionName(Value As Variant) As String
If Not IsNull(Value) Then RegionName = Split(Value, " ")(2)
End Function
调用它:
SELECT RegionName(T.Region) AS _RegionName
FROM T;
结果:
'Input: Vic - Melbourne Central
'Output: Melbourne
这篇关于在访问报告中为“分组依据"字段添加别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!