Microsoft Access和Visual Basic - 需要帮助运行模块(Microsoft Access and Visual Basic - Need help running module)

我需要帮助我正在尝试创建的微软访问应用程序。 我创建了一个获取许多日期的数据库。 我需要计算日期之间的天数,以及OMIT星期二,星期四,星期六和星期日在柜台。 这是在两个不同的时间间隔(NotificationDate到OrderDate)和(PlacementDate到ReleaseDate)之间

我的问题是,现在我写了它,我如何在Microsoft Access中实际使用它? 如何从表单中运行它?

'//////This is for Valley Estimate of Demurrage Days///////////// Public Function Weekdays(ByRef NotificationDate As Date, ByRef OrderDate As Date, ByRef PlacementDate As Date, ByRef ReleaseDate As Date) As Integer Dim numWeekdays As Integer Dim totalDays As Integer Dim totaldays2 As Integer Dim WeekendDays As Integer Dim WeekendDays2 As Integer numWeekdays = 0 WeekendDays = 0 WeekendDays2 = 0 totalDays = DateDiff(dateinterval.Day, NotificationDate, OrderDate) + 1 'for i as integer = 1 to totalDays If DatePart(dateinterval.Weekday, NotificationDate) = 1 Then WeekendDays = WeekendDays + 1 End If If DatePart(dateinterval.Weekday, startDateNotificationDate) = 3 Then WeekendDays = WeekendDays + 1 End If If DatePart(dateinterval.Weekday, NotificationDate) = 5 Then WeekendDays = WeekendDays + 1 End If If DatePart(dateinterval.Weekday, NotificationDate) = 7 Then WeekendDays = WeekendDays + 1 End If NotificationDate = DateAdd("d", 1, NotificationDate) '/////////////////////////////////////////////////////////////////////////// totaldays2 = DateDiff(dateinterval.Day, PlacementDate, ReleaseDate) + 1 If DatePart(dateinterval.Weekday, PlacementDate) = 1 Then WeekendDays2 = WeekendDays2 + 1 End If If DatePart(dateinterval.Weekday, PlacementDate) = 3 Then WeekendDays2 = WeekendDays2 + 1 End If If DatePart(dateinterval.Weekday, PlacementDate) = 5 Then WeekendDays2 = WeekendDays2 + 1 End If If DatePart(dateinterval.Weekday, PlacementDate) = 7 Then WeekendDays2 = WeekendDays2 + 1 End If PlacementDate = DateAdd("d", 1, PlacementDate) numWeekdays = WeekendDays + WeekendDays2 End Function

I need help with a microsoft access application I am trying to create. I created a database that gets a number of dates. I need to count the number of days between the dates, and OMIT Tuesdays, Thursdays, Saturdays and Sundays in the counter. This is between two separate time intervals (NotificationDate to OrderDate) and (PlacementDate to ReleaseDate)

My question is, now that I wrote it, how do I actually use it in Microsoft Access?? How do I run it from a form?

'//////This is for Valley Estimate of Demurrage Days///////////// Public Function Weekdays(ByRef NotificationDate As Date, ByRef OrderDate As Date, ByRef PlacementDate As Date, ByRef ReleaseDate As Date) As Integer Dim numWeekdays As Integer Dim totalDays As Integer Dim totaldays2 As Integer Dim WeekendDays As Integer Dim WeekendDays2 As Integer numWeekdays = 0 WeekendDays = 0 WeekendDays2 = 0 totalDays = DateDiff(dateinterval.Day, NotificationDate, OrderDate) + 1 'for i as integer = 1 to totalDays If DatePart(dateinterval.Weekday, NotificationDate) = 1 Then WeekendDays = WeekendDays + 1 End If If DatePart(dateinterval.Weekday, startDateNotificationDate) = 3 Then WeekendDays = WeekendDays + 1 End If If DatePart(dateinterval.Weekday, NotificationDate) = 5 Then WeekendDays = WeekendDays + 1 End If If DatePart(dateinterval.Weekday, NotificationDate) = 7 Then WeekendDays = WeekendDays + 1 End If NotificationDate = DateAdd("d", 1, NotificationDate) '/////////////////////////////////////////////////////////////////////////// totaldays2 = DateDiff(dateinterval.Day, PlacementDate, ReleaseDate) + 1 If DatePart(dateinterval.Weekday, PlacementDate) = 1 Then WeekendDays2 = WeekendDays2 + 1 End If If DatePart(dateinterval.Weekday, PlacementDate) = 3 Then WeekendDays2 = WeekendDays2 + 1 End If If DatePart(dateinterval.Weekday, PlacementDate) = 5 Then WeekendDays2 = WeekendDays2 + 1 End If If DatePart(dateinterval.Weekday, PlacementDate) = 7 Then WeekendDays2 = WeekendDays2 + 1 End If PlacementDate = DateAdd("d", 1, PlacementDate) numWeekdays = WeekendDays + WeekendDays2 End Function

最满意答案

您可以通过在TextBox的ControlSource中输入表达式来显示表达式的结果。 前面加上“=”。

=Weekdays(CDate([txtNotificationDate]), CDate([txtOrderDate]), CDate([txtPlacementDate]), CDate([txtReleaseDate]))

(在一条线上)

请注意,您只需在表达式中输入其名称即可访问TextBoxes(以及当前Form的其他控件)。 Access将自动添加方括号[]。

如果Access不应自动更新结果TextBox,则可以强制重新计算它

Me!txtResult.Requery

但在大多数情况下,Access会自动更新它。

You can show the result of an expression by entering it in the ControlSource of a TextBox. Prepend it with "=".

=Weekdays(CDate([txtNotificationDate]), CDate([txtOrderDate]), CDate([txtPlacementDate]), CDate([txtReleaseDate]))

(on one line)

Note that you can access the TextBoxes (and other controls of the current Form) by just entering their names in the expression. Access will add the brackets [] automatically.

If Access should not update the result TextBox automatically, you can force the recalculation of it with

Me!txtResult.Requery

But in most situations Access will update it automatically.

Microsoft Access和Visual Basic - 需要帮助运行模块(Microsoft Access and Visual Basic - Need help running module)

我需要帮助我正在尝试创建的微软访问应用程序。 我创建了一个获取许多日期的数据库。 我需要计算日期之间的天数,以及OMIT星期二,星期四,星期六和星期日在柜台。 这是在两个不同的时间间隔(NotificationDate到OrderDate)和(PlacementDate到ReleaseDate)之间

我的问题是,现在我写了它,我如何在Microsoft Access中实际使用它? 如何从表单中运行它?

'//////This is for Valley Estimate of Demurrage Days///////////// Public Function Weekdays(ByRef NotificationDate As Date, ByRef OrderDate As Date, ByRef PlacementDate As Date, ByRef ReleaseDate As Date) As Integer Dim numWeekdays As Integer Dim totalDays As Integer Dim totaldays2 As Integer Dim WeekendDays As Integer Dim WeekendDays2 As Integer numWeekdays = 0 WeekendDays = 0 WeekendDays2 = 0 totalDays = DateDiff(dateinterval.Day, NotificationDate, OrderDate) + 1 'for i as integer = 1 to totalDays If DatePart(dateinterval.Weekday, NotificationDate) = 1 Then WeekendDays = WeekendDays + 1 End If If DatePart(dateinterval.Weekday, startDateNotificationDate) = 3 Then WeekendDays = WeekendDays + 1 End If If DatePart(dateinterval.Weekday, NotificationDate) = 5 Then WeekendDays = WeekendDays + 1 End If If DatePart(dateinterval.Weekday, NotificationDate) = 7 Then WeekendDays = WeekendDays + 1 End If NotificationDate = DateAdd("d", 1, NotificationDate) '/////////////////////////////////////////////////////////////////////////// totaldays2 = DateDiff(dateinterval.Day, PlacementDate, ReleaseDate) + 1 If DatePart(dateinterval.Weekday, PlacementDate) = 1 Then WeekendDays2 = WeekendDays2 + 1 End If If DatePart(dateinterval.Weekday, PlacementDate) = 3 Then WeekendDays2 = WeekendDays2 + 1 End If If DatePart(dateinterval.Weekday, PlacementDate) = 5 Then WeekendDays2 = WeekendDays2 + 1 End If If DatePart(dateinterval.Weekday, PlacementDate) = 7 Then WeekendDays2 = WeekendDays2 + 1 End If PlacementDate = DateAdd("d", 1, PlacementDate) numWeekdays = WeekendDays + WeekendDays2 End Function

I need help with a microsoft access application I am trying to create. I created a database that gets a number of dates. I need to count the number of days between the dates, and OMIT Tuesdays, Thursdays, Saturdays and Sundays in the counter. This is between two separate time intervals (NotificationDate to OrderDate) and (PlacementDate to ReleaseDate)

My question is, now that I wrote it, how do I actually use it in Microsoft Access?? How do I run it from a form?

'//////This is for Valley Estimate of Demurrage Days///////////// Public Function Weekdays(ByRef NotificationDate As Date, ByRef OrderDate As Date, ByRef PlacementDate As Date, ByRef ReleaseDate As Date) As Integer Dim numWeekdays As Integer Dim totalDays As Integer Dim totaldays2 As Integer Dim WeekendDays As Integer Dim WeekendDays2 As Integer numWeekdays = 0 WeekendDays = 0 WeekendDays2 = 0 totalDays = DateDiff(dateinterval.Day, NotificationDate, OrderDate) + 1 'for i as integer = 1 to totalDays If DatePart(dateinterval.Weekday, NotificationDate) = 1 Then WeekendDays = WeekendDays + 1 End If If DatePart(dateinterval.Weekday, startDateNotificationDate) = 3 Then WeekendDays = WeekendDays + 1 End If If DatePart(dateinterval.Weekday, NotificationDate) = 5 Then WeekendDays = WeekendDays + 1 End If If DatePart(dateinterval.Weekday, NotificationDate) = 7 Then WeekendDays = WeekendDays + 1 End If NotificationDate = DateAdd("d", 1, NotificationDate) '/////////////////////////////////////////////////////////////////////////// totaldays2 = DateDiff(dateinterval.Day, PlacementDate, ReleaseDate) + 1 If DatePart(dateinterval.Weekday, PlacementDate) = 1 Then WeekendDays2 = WeekendDays2 + 1 End If If DatePart(dateinterval.Weekday, PlacementDate) = 3 Then WeekendDays2 = WeekendDays2 + 1 End If If DatePart(dateinterval.Weekday, PlacementDate) = 5 Then WeekendDays2 = WeekendDays2 + 1 End If If DatePart(dateinterval.Weekday, PlacementDate) = 7 Then WeekendDays2 = WeekendDays2 + 1 End If PlacementDate = DateAdd("d", 1, PlacementDate) numWeekdays = WeekendDays + WeekendDays2 End Function

最满意答案

您可以通过在TextBox的ControlSource中输入表达式来显示表达式的结果。 前面加上“=”。

=Weekdays(CDate([txtNotificationDate]), CDate([txtOrderDate]), CDate([txtPlacementDate]), CDate([txtReleaseDate]))

(在一条线上)

请注意,您只需在表达式中输入其名称即可访问TextBoxes(以及当前Form的其他控件)。 Access将自动添加方括号[]。

如果Access不应自动更新结果TextBox,则可以强制重新计算它

Me!txtResult.Requery

但在大多数情况下,Access会自动更新它。

You can show the result of an expression by entering it in the ControlSource of a TextBox. Prepend it with "=".

=Weekdays(CDate([txtNotificationDate]), CDate([txtOrderDate]), CDate([txtPlacementDate]), CDate([txtReleaseDate]))

(on one line)

Note that you can access the TextBoxes (and other controls of the current Form) by just entering their names in the expression. Access will add the brackets [] automatically.

If Access should not update the result TextBox automatically, you can force the recalculation of it with

Me!txtResult.Requery

But in most situations Access will update it automatically.