Hi Group:
I have a custom function that I want to call from a query that will convert a short date to the following "2006 - 01". The code below is used to open a fiscal calandar within a static table called tblCalandar. Based on the accounting calandar, it will sort to the current fiscal period of tblCalandar. An example would be if today was 1/29/2006 then it would fall into the February period. I want to read the transaction date in my 1st query like this YearMonth([#1/29/2006]) and return 2006-02 based on the SQL in the code below.
Private Function YearMonth(Yr, Mn)
'Assigns the accounting month at the time cash is entered
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Set conn = CurrentProject.Connection
Set rs = New ADODB.Recordset
strSQL = "SELECT TOP 1 tblCalandar.AMonth, tblCalandar.AYear, tblCalandar.Month FROM tblCalandar WHERE (((tblCalandar.AEnd) >= Date)) ORDER BY tblCalandar.AEnd;"
rs.Open strSQL, CurrentProject.Connection, adOpenStatic
Yr = AYear *** this doesn't work
Mn = AMonth *** this doesn't work
rs.Close
Set rs = Nothing
conn.Close
What am I missing in the function that make this work?
I have a custom function that I want to call from a query that will convert a short date to the following "2006 - 01". The code below is used to open a fiscal calandar within a static table called tblCalandar. Based on the accounting calandar, it will sort to the current fiscal period of tblCalandar. An example would be if today was 1/29/2006 then it would fall into the February period. I want to read the transaction date in my 1st query like this YearMonth([#1/29/2006]) and return 2006-02 based on the SQL in the code below.
Private Function YearMonth(Yr, Mn)
'Assigns the accounting month at the time cash is entered
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Set conn = CurrentProject.Connection
Set rs = New ADODB.Recordset
strSQL = "SELECT TOP 1 tblCalandar.AMonth, tblCalandar.AYear, tblCalandar.Month FROM tblCalandar WHERE (((tblCalandar.AEnd) >= Date)) ORDER BY tblCalandar.AEnd;"
rs.Open strSQL, CurrentProject.Connection, adOpenStatic
Yr = AYear *** this doesn't work
Mn = AMonth *** this doesn't work
rs.Close
Set rs = Nothing
conn.Close
What am I missing in the function that make this work?