Hi, Im attempting to run a query over a remote Db400 table using MS Access'97 where i need to specify the from and to date. Depending on the current date, the required dates will change so I'm using VB to calculate the day number, to then calculate the from and to dates. The function is called by a query, but it fails on a type mismatch as the target field must be defined as a integer. Given this happens, is there an alternative solution, appreciate as much detail as possible as im not very familiar with writing a sql statement.
Code:
Public Function CalcDelDate() As String Dim FromDelDate As Variant Dim ToDelDate As Variant Dim Today As Variant Dim MyDate As String Dim Interval As String Dim FromDate As String Dim ToDate As String 'This procedure calculates the date for the following days deliveries 'Calculate what the Day Number is from todays date 'Where today is a Friday, add 3 days to get to Mondays date 'Where today is a Saturday, add 2 days to get to Mondays date Today = WeekDay(Date) If Today = 6 Then FromDelDate = DateAdd("d", "1", Date) ToDelDate = DateAdd("d", "3", Date) ElseIf Today = 7 Then FromDelDate = DateAdd("d", "2", Date) ToDelDate = DateAdd("d", "2", Date) Else FromDelDate = DateAdd("d", "1", Date) ToDelDate = DateAdd("d", "1", Date) End If 'Now Format the calculated date prefixing with a '1' to match as/400 date format FromDate = Format(FromDelDate, "1yymmdd") ToDate = Format(ToDelDate, "1yymmdd") CalcDelDate = ">=" & FromDate & " And " & "<=" & ToDate
Comment