A
arnold roth
I'm attempting to calculate some dates in a database
query. The problem is to determine a date based on two
fields, a date and a string. In this case, the string is
a verification method and the date is the expected date on
which the method is employed.
I've written a simple function to calculate the dates as
follows:
Function Date_Calculate(test_type As String, date_1 As
Date) _
As Date
'Print test_type
'Print date_1
Select Case test_type
Case "Test"
Date_Calculate = date_1 + 30
Case "Demonstration"
Date_Calculate = date_1 + 20
Case "Inspection", "Examination"
Date_Calculate = date_1 + 10
Case "Analysis"
Date_Calculate = date_1 + 40
Case Else
Date_Calculate = date_1
MsgBox ("No Verification Method Specified."
& Chr(13) _
& "Please specify a method.")
End Select
End Function
The function is called from a query as follows:
Date_Calculate([Verification Methods]![NG ACC METH],CDate
([Verification Events]![Event_Date])).
In the database tables, NG ACC METH is a text field and
Event_Date is a short date field.
There are two problems:
1. The MsgBox code will not compile. Get an error message
about being out of the Type box (or something like that).
I also cannot add debug print statements inside the
function without getting compiler errors.
2. The function produces #err in every record when it is
run. The only way to make it work is to replace the date
input with a hard coded date as datevalue("string").
Can anyone tell me what I'm doing wrong, or better, how to
make it right?
Many thanks
query. The problem is to determine a date based on two
fields, a date and a string. In this case, the string is
a verification method and the date is the expected date on
which the method is employed.
I've written a simple function to calculate the dates as
follows:
Function Date_Calculate(test_type As String, date_1 As
Date) _
As Date
'Print test_type
'Print date_1
Select Case test_type
Case "Test"
Date_Calculate = date_1 + 30
Case "Demonstration"
Date_Calculate = date_1 + 20
Case "Inspection", "Examination"
Date_Calculate = date_1 + 10
Case "Analysis"
Date_Calculate = date_1 + 40
Case Else
Date_Calculate = date_1
MsgBox ("No Verification Method Specified."
& Chr(13) _
& "Please specify a method.")
End Select
End Function
The function is called from a query as follows:
Date_Calculate([Verification Methods]![NG ACC METH],CDate
([Verification Events]![Event_Date])).
In the database tables, NG ACC METH is a text field and
Event_Date is a short date field.
There are two problems:
1. The MsgBox code will not compile. Get an error message
about being out of the Type box (or something like that).
I also cannot add debug print statements inside the
function without getting compiler errors.
2. The function produces #err in every record when it is
run. The only way to make it work is to replace the date
input with a hard coded date as datevalue("string").
Can anyone tell me what I'm doing wrong, or better, how to
make it right?
Many thanks