Hello everyone, I have an issue with a table embedded in a form, with a query that changes based on what is done in the form. The problem is a bit long, so please bear with me.
I have a table of events, tblActivitiesDates which have an activity type and a date.
I have a form which has a datasheet with a query source (a separate datasheet form embedded in this one), and 2 radio buttons. The query that is used uses radio buttons this way:
-Activity Type Filter: A radio button, that when clicked a combo box appears, with a list of activity types to choose from. Basically, filtering by Activity Type.
-Date Type Filter: A radio button, that when clicked 2 text boxes appear, in which you write the dates between which you want to see the events organized in the table. Basically filtering by dates.
HOW IT WORKS:
To make reading easier, Activity Type Filter=ATF, Data Type Filter=DTF.
There are 4 possible options:
-ATF=ON and DTF=ON
-ATF=ON and DTF=OFF
-ATF=OFF and DTF=ON
-ATF=OFF and DTF=OFF.
For each option, I have written a line of code in the appropriate OnChange/AfterUpdate/Whatnot events in the form:
CurrentDb.QueryDef("qryActivitiesDates").SQL = "SELECT..."
according to whatever option is currently active.
THE PROBLEM:
IMPORTANT: When I enter values into the form, and instead of embedding my datasheet form I simply open it every time from the navigation pane in a new window, the datasheet is filled appropriately and works 100%. Of course, I have to reopen it every time I change something so the query will rerun.
When the datasheet is embedded though, I have the following problem:
After the table crashes (will be explained soon), I re-embed it to the form before trying it again. The first time I re-embed, no matter what I do, the query doesn't update nor crash. It's pretty much dead. The second time I re-embed, this is what happens:
Say I start with the option ATF=ON, DTF=OFF, it will work fine, updating when needed, but if I tick DTF=ON, regardless of the dates I enter, the table will only change according to the first option (While when open in a new window will show the correct table entries), ignoring the fact that the QueryDef.Sql has changed. Once I tick ATF=OFF, the table crashes and I get the error:"Run-time error'3420': Object invalid or no longer set".
The exact same thing happens when I go DTF=ON,ATF=OFF. It ignores the event types I enter, and once I tick DTF=OFF, it crashes with the exact same error.
Please note that I added Me.Activities_DS.Form.Requery (datasheet's name is Activities_DS) in every place it should update.
For your convenience, I'm trying to keep my thread as concise as possible (Because nobody likes reading walls of text). For that reason, I'm not immediately posting all my code. If there's any info/code you want to see, please just ask, and I will reply immediately with everything I can offer.
Sincerly, Guy.
I have a table of events, tblActivitiesDates which have an activity type and a date.
I have a form which has a datasheet with a query source (a separate datasheet form embedded in this one), and 2 radio buttons. The query that is used uses radio buttons this way:
-Activity Type Filter: A radio button, that when clicked a combo box appears, with a list of activity types to choose from. Basically, filtering by Activity Type.
-Date Type Filter: A radio button, that when clicked 2 text boxes appear, in which you write the dates between which you want to see the events organized in the table. Basically filtering by dates.
HOW IT WORKS:
To make reading easier, Activity Type Filter=ATF, Data Type Filter=DTF.
There are 4 possible options:
-ATF=ON and DTF=ON
-ATF=ON and DTF=OFF
-ATF=OFF and DTF=ON
-ATF=OFF and DTF=OFF.
For each option, I have written a line of code in the appropriate OnChange/AfterUpdate/Whatnot events in the form:
CurrentDb.QueryDef("qryActivitiesDates").SQL = "SELECT..."
according to whatever option is currently active.
THE PROBLEM:
IMPORTANT: When I enter values into the form, and instead of embedding my datasheet form I simply open it every time from the navigation pane in a new window, the datasheet is filled appropriately and works 100%. Of course, I have to reopen it every time I change something so the query will rerun.
When the datasheet is embedded though, I have the following problem:
After the table crashes (will be explained soon), I re-embed it to the form before trying it again. The first time I re-embed, no matter what I do, the query doesn't update nor crash. It's pretty much dead. The second time I re-embed, this is what happens:
Say I start with the option ATF=ON, DTF=OFF, it will work fine, updating when needed, but if I tick DTF=ON, regardless of the dates I enter, the table will only change according to the first option (While when open in a new window will show the correct table entries), ignoring the fact that the QueryDef.Sql has changed. Once I tick ATF=OFF, the table crashes and I get the error:"Run-time error'3420': Object invalid or no longer set".
The exact same thing happens when I go DTF=ON,ATF=OFF. It ignores the event types I enter, and once I tick DTF=OFF, it crashes with the exact same error.
Please note that I added Me.Activities_DS.Form.Requery (datasheet's name is Activities_DS) in every place it should update.
For your convenience, I'm trying to keep my thread as concise as possible (Because nobody likes reading walls of text). For that reason, I'm not immediately posting all my code. If there's any info/code you want to see, please just ask, and I will reply immediately with everything I can offer.
Sincerly, Guy.