Hi Orange - hope all good.
I have made a lot of progress and I am trying to tackle a problem and have hit a brick wall. Please could you help me
THE PROBLEM
- Currently the stack of FIFO queries use the criteria reference "<=[forms]![frmReports]![TDate]" (use QryAvailableStock as example)
- I am using this same set of queries to generate output for other forms (not just the reports)
- This means I need to have the Report form open at the same time as the other forms using this query to prevent an Enter Parameter request
PROPOSED SOLUTION I AM WORKING ON
- I have thought the best approach would be to create a global variable called "TDate" value to be stored as a global variable and then I can update the query criteria to "<=[TDate]"
- The SetTDate function can set the date to today when starting the application and so I can use the FIFO queries on other forms (without the Report form needing to be open)
- But where the Reports need other FDate and TDate, I am using an after update event on those unbound fields of the Reports form to set the global variable.
- This all works.
RESULT SO FAR
- I have created a global variable and set up functions to set the TDate
Module 1: "DeclareGlobalDateVariables" with the code
Option Compare Database
Global TDate As Date
Global FDate As Date
Module 2: "DateFunctions" with the code
Option Compare Database
Public Function SetTDate()
TDate = Date
End Function
Public Function SetFDate()
FDate = Date
End Function
- To test, I have created a blank form with a button. The msgbox gives the correct value ie. todays date.
Private Sub Command3_Click()
SetTDateMsgBox Format(TDate, "Short Date")
DoCmd.OpenQuery "QryStockAvailable"
End Sub
ERROR
- when the above is button clicked, I get an Enter Parameter Value request for "TDate"
TROUBLESHOOTING
- I have tried to use various syntax for the criteria eg. [TDate], TDate, [DeclareGlobalDateVariables].[TDate] etc. Nothing seems to work.
- I have read this post which speaks about the fact that you cannot use a public or global variable directly in a query but I am not sure how to use this infomation. Perhaps this is useful for you to look at: https://www.experts-exchange.com/art...MS-Access.html
- Note that I previously declared the variable as a Public variable ie. Public TDate As Date but it had the same errors
Please can you help me get this to work - it is a real roadblock for me