我正在建立一个访问中的房间预订系统,我需要一些关于查询的宏的帮助。
这是人们在预订房间时会看到的形式:
这很好用。
我所做的是创建一个查询,根据日期,返回特定房间的预定时间。
此特定查询适用于今天的111室。所以在这里,它显示今天,第111和第6期的第111室不可用。
我需要编写一个宏来查看每一行,并清空表单上的相关文本框控件。
所以它应该看起来像这样:
我不知道这是否可以使用宏,或者我是否需要使用Visual Basic。我只需要让宏/代码说:
" FOR Each Row,IF 111ScheduleCheck.TimeSlot =" Period 1&#34 ;,那么FORMAT 111_P1 TO Background = Black"
"对于每一行,IF 111ScheduleCheck.TimeSlot =" Period 2",那么格式111_P2 TO Background = Black"
等等
我已经尝试过这个但是它没有用:
有人可以帮我这么做吗?
谢谢,
罗文:)
答案 0 :(得分:1)
考虑将表单绑定到下面的连续/多项表单上的透视查询,其中文本框将作为带有Room字段的Period字段。此外,可能还有空间来规范化所有会议室将使用一个Schedule表的表,从而避免在联合查询下面。
SELECT dT.Room, dT.Day,
Max(IIF(dT.[Time Slot] = 'Period 1', 'Yes', NULL)) AS [Period 1],
Max(IIF(dT.[Time Slot] = 'Period 2', 'Yes', NULL)) AS [Period 2],
Max(IIF(dT.[Time Slot] = 'Period 3', 'Yes', NULL)) AS [Period 3],
Max(IIF(dT.[Time Slot] = 'Period 4', 'Yes', NULL)) AS [Period 4],
Max(IIF(dT.[Time Slot] = 'Period 5', 'Yes', NULL)) AS [Period 5],
Max(IIF(dT.[Time Slot] = 'Period 6', 'Yes', NULL)) AS [Period 6]
FROM
(SELECT 'Room 111' As Room, [Day], [Time Slot] FROM Schedule111
UNION SELECT 'Room 121' As Room, [Day], [Time Slot] FROM Schedule121
UNION SELECT 'Room 122' As Room, [Day], [Time Slot] FROM Schedule122
UNION SELECT 'Room 125' As Room, [Day], [Time Slot] FROM Schedule125) AS dT
GROUP BY dT.Room, dT.Day
然后conditionally format六个Period文本框中的每一个都带有背景颜色:
[Field Value Is] equal to "Yes".
最后,使用表单的OnCurrent触发器事件按当前页面的日期值过滤表单。确保日期标题控件是真正的日期格式文本框:
DoCmd.ApplyFilter , "[Day]='" _
& WeekdayName(WeekDay(Forms!YourForm!YourDateControl,2)) &"'")