周五提醒我周末应该看什么

发布于 2024-08-08 13:52:40 字数 645 浏览 10 评论 0原文

我在不同的监禁中设置了以下查询,以提醒我合同在确认的到期日期前 0、7、30、60 和 90 天到期。我计算通知日期的方法没有给我任何灵活性。例如,假设我有 30 份合同将于 12 月 5 日到期,周六我的办公室不上班。我会错过合同当天和 7 天后到期的通知。

SELECT qryAllSold.SoldID, qryAllSold.CompanyName, qryAllSold.Product, qryAllSold.Description, qryAllSold.Quantity, qryAllSold.Price, qryAllSold.ConfirmedExpires, qryAllSold.Note
FROM qryAllSold
WHERE (((qryAllSold.ConfirmedExpires)=DateAdd("d",0,Int(Now()))) AND ((qryAllSold.RenewedToID) Is Null) AND ((qryAllSold.NonOpportunity)=No));

这些查询中的每一个都将显示在一个“仪表板”表单上,作为每日任务列表。如果我可以让表单代表日期,然后单击箭头一次向前或向后移动一天,那就太好了,但我不知道 Access 是否具有该功能。

如果这不起作用,还有什么其他方法可以确保我不会错过有关这些到期的通知?

I have the following query set up, in various incarcerations, to remind me of contract expirations 0, 7, 30, 60, and 90 days before the confirmed expiration date. My method of calculating the notification date doesn't give me any flexibility. For example, say I have 30 contracts expiring 12/5, a Saturday when my office isn't open. I will miss the notification that the contract expired that day, and 7 days out.

SELECT qryAllSold.SoldID, qryAllSold.CompanyName, qryAllSold.Product, qryAllSold.Description, qryAllSold.Quantity, qryAllSold.Price, qryAllSold.ConfirmedExpires, qryAllSold.Note
FROM qryAllSold
WHERE (((qryAllSold.ConfirmedExpires)=DateAdd("d",0,Int(Now()))) AND ((qryAllSold.RenewedToID) Is Null) AND ((qryAllSold.NonOpportunity)=No));

Each of these queries will be displayed on one "dashboard" form to serve as a daily task list. It would be great if I could have the form represent a date, and click an arrow to move forward or back a day at a time, but I don't know if Access has that capability.

If that won't work, what other ways can I make sure I don't miss notifications on these expirations?

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

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

发布评论

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

评论(2

妥活 2024-08-15 13:52:40

[编辑]如果您不是程序员,这里有一个替代解决方案

为什么不在查询中使用Format函数,例如

Format([ConfirmedExpires],"ww",2,1)

“ww”-指定周,2指定星期一为一周的第一天,1 表示第 1 周包含 1 月 1 日

现在很容易以周为单位进行日期计算,例如,合同在未来 4 周以上到期:

Format([ConfirmedExpires],"ww",2,1)-Format(Now(),"ww",2,1))>4

合同在未来 4 周以上到期,最多 5 周后到期future

Format([ConfirmedExpires],"ww",2,1)-Format(Now(),"ww",2,1))>4 -
Format([ConfirmedExpires],"ww",2,1)-Format(Now(),"ww",2,1)),=5

这有帮助吗?


为什么不直接使用 DateAdd 等函数的工作日功能呢?

您可以计算 25 天或任何其他数量的工作日,而不是提前计算 30 个日历日。

下面的代码显示一个消息框,但您同样可以在消息框后面的 SQL 查询中使用该函数。

Sub TestWeekDay()
    Dim FirstDate As Date    ' Declare variables.
    Dim IntervalType As String
    Dim Number As Integer
    Dim Msg

    IntervalType = "ww"    ' "ww" specifies weeks as interval.
    FirstDate = InputBox("Enter a date")
    Number = InputBox("Enter number of weekdays to add")
    Msg = "New date: " & DateAdd(IntervalType, Number, FirstDate)
    MsgBox Msg
End Sub

[EDIT] If you are not a programmer here is an alternative solution

Why not use the Format function in your query, e.g.

Format([ConfirmedExpires],"ww",2,1)

"ww" - specifies weeks, 2 specifies Monday as first day of the week, 1 means week 1 contains 1 Jan

Now it is easy to do date calculations in weeks e.g. Contract expiring more than 4 weeks into the future:

Format([ConfirmedExpires],"ww",2,1)-Format(Now(),"ww",2,1))>4

Contracts expiring more than 4 weeks into the future and up to 5 weeks into the future

Format([ConfirmedExpires],"ww",2,1)-Format(Now(),"ww",2,1))>4 -
Format([ConfirmedExpires],"ww",2,1)-Format(Now(),"ww",2,1)),=5

Does that help?


Why don't you just use the weekday feature of functions like DateAdd?

Instead of calculating 30 calendar days ahead you could calculate 25, or any other number of weekdays ahead.

The code below displays a message box but you could equally use the function in a SQL query behind a message box.

Sub TestWeekDay()
    Dim FirstDate As Date    ' Declare variables.
    Dim IntervalType As String
    Dim Number As Integer
    Dim Msg

    IntervalType = "ww"    ' "ww" specifies weeks as interval.
    FirstDate = InputBox("Enter a date")
    Number = InputBox("Enter number of weekdays to add")
    Msg = "New date: " & DateAdd(IntervalType, Number, FirstDate)
    MsgBox Msg
End Sub
凤舞天涯 2024-08-15 13:52:40

也许有点复杂:

IIf(Weekday(DateAdd("d", 0, Date())) = 7, DateAdd("d", 0, Date()) + 2, IIf(Weekday(DateAdd("d", 0, Date())) = 1, DateAdd("d", 0, Date()) + 1, DateAdd("d", 0, Date())))

这可以放在您的 where 语句中,如下所示:

SELECT q.SoldID, q.CompanyName, q.Product, 
       q.Description, q.Quantity, q.Price, 
       q.ConfirmedExpires, q.Note
FROM qryAllSold AS q
WHERE q.ConfirmedExpires=IIf(Weekday(DateAdd("d", 0, Date())) = 7, DateAdd("d", 0, Date()) + 2, IIf(Weekday(DateAdd("d", 0, Date())) = 1, DateAdd("d", 0, Date()) + 1, DateAdd("d", 0, Date())))
AND q.RenewedToID Is Null AND q.NonOpportunity=No

请注意,我使用了 qryAllSold 的别名 q,因为这可以更轻松地读取查询:
FROM qryAllSold AS q

最好使用 False 而不是 No。

如果您愿意,您应该能够使用参数:

PARAMETERS NoDays Short;
SELECT q.SoldID, q.CompanyName, q.Product, 
       q.Description, q.Quantity, q.Price, 
       q.ConfirmedExpires, q.Note
FROM qryAllSold AS q
WHERE q.ConfirmedExpires=IIf(Weekday(DateAdd("d",[NoDays],Date()))=7,DateAdd("d",[NoDays],Date())+2,IIf(Weekday(DateAdd("d",[NoDays],Date()))=1,DateAdd("d",[NoDays],Date())+1,DateAdd("d",[NoDays],Date())))
AND q.RenewedToID Is Null AND q.NonOpportunity=No

该参数允许您选择天数。如果它引用表单上的字段或在 VBA 中设置,那就更好了。

Perhaps a little complication:

IIf(Weekday(DateAdd("d", 0, Date())) = 7, DateAdd("d", 0, Date()) + 2, IIf(Weekday(DateAdd("d", 0, Date())) = 1, DateAdd("d", 0, Date()) + 1, DateAdd("d", 0, Date())))

This can be put in your where statement, like so:

SELECT q.SoldID, q.CompanyName, q.Product, 
       q.Description, q.Quantity, q.Price, 
       q.ConfirmedExpires, q.Note
FROM qryAllSold AS q
WHERE q.ConfirmedExpires=IIf(Weekday(DateAdd("d", 0, Date())) = 7, DateAdd("d", 0, Date()) + 2, IIf(Weekday(DateAdd("d", 0, Date())) = 1, DateAdd("d", 0, Date()) + 1, DateAdd("d", 0, Date())))
AND q.RenewedToID Is Null AND q.NonOpportunity=No

Note that I have used the alias q for qryAllSold as this makes it easier to read the query:
FROM qryAllSold AS q

It would probably be best to use False instead of No.

If you wish, you should be able to use a parameter:

PARAMETERS NoDays Short;
SELECT q.SoldID, q.CompanyName, q.Product, 
       q.Description, q.Quantity, q.Price, 
       q.ConfirmedExpires, q.Note
FROM qryAllSold AS q
WHERE q.ConfirmedExpires=IIf(Weekday(DateAdd("d",[NoDays],Date()))=7,DateAdd("d",[NoDays],Date())+2,IIf(Weekday(DateAdd("d",[NoDays],Date()))=1,DateAdd("d",[NoDays],Date())+1,DateAdd("d",[NoDays],Date())))
AND q.RenewedToID Is Null AND q.NonOpportunity=No

The parameter allows you to pick a number of days. It would be even better if this referred to a field on a form or was set in VBA.

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