AOB
Registered User.
- Local time
- Today, 00:08
- Joined
- Sep 26, 2012
- Messages
- 633
Hi guys,
I'll try my best to explain this one but I'm stumped as to the cause...
I have a form with two continuous subforms. The records returned in the first subform will each have multiple associated records from another dataset, which are displayed in the second subform.
To achieve this, I have a command button for each row of the first subform. Clicking on it takes the identifier for the selected record and passes it to a hidden textbox on the main form. The second subform uses the value in that hidden textbox as the criteria for its own query. This allows me to effectively pass a selected value from the first subform over to the second subform, via the common parent.
Using the OnClick event of the command button, the code checks the hidden textbox in the main form. If it already holds the value it was going to pass, the hidden textbox is cleared (in other words, the user is deselecting that record). If it doesn't, it passes the value (the user is selecting that record)
The query for the second subform therefore looks something like this :
So if the hidden textbox is empty (no record selected) the query returns an empty dataset (the ID will never be 0) for the second subform. Otherwise, the query returns any records associated with that ID.
Works fine everywhere else I've used this approach
However, with my latest form, I need to use 3 hidden textboxes (this is just the quickest / easiest way given the complexity of the related tables)
Same basic principle though, only difference being that on clicking the command button in the first subform, I pass 3 values to 3 hidden textboxes (one ID and two dates) Or, if the ID is already present (already selected), I clear all 3.
And then the query for the second subform looks like this :
Again, the theory is that if the hidden ID textbox is empty (no record selected) the query returns a blank dataset (the ID will never be 0 and no date can fall in that range) for the second subform. Otherwise, the query returns the records associated with that ID and between those dates.
Here's the problem (finally!!)
The functionality works fine initially. When the form loads, the first subform has records, the second subform is empty (no record selected yet) When I select a record from the first subform, the second subform populates with the correct results associated. When I change my selection in the first subform, the second subform updates accordingly.
But when I deselect from the first subform (and empty all the hidden textboxes) the second subform displays "#Name?" across all the visible controls and after a couple of seconds I get the following error :
(I actually get this error several times, with random delays in between, until I close the form)
At this point, selecting / deselecting records in the first subform has no effect, the second subform is basically defunct. If I close the form and reopen it, everything's back to normal again.
I have fairly extensive error handling throughout the DB but it is not firing (i.e. it is not logging the error to my error table) so it's difficult to pinpoint exactly where I need to focus my attention.
What's weird is, I use this method of passing values between subforms via hidden textboxes on the common parent quite a bit and it works seamlessly everywhere else. The only difference I can see here is that I'm passing 3 'hidden' values instead of one?
Can anybody make a suggestion as to what I should be checking?
Thanks & apologies for the long-winded synopsis; if you've made it this far, I thank you for your patience!
Al
I'll try my best to explain this one but I'm stumped as to the cause...
I have a form with two continuous subforms. The records returned in the first subform will each have multiple associated records from another dataset, which are displayed in the second subform.
To achieve this, I have a command button for each row of the first subform. Clicking on it takes the identifier for the selected record and passes it to a hidden textbox on the main form. The second subform uses the value in that hidden textbox as the criteria for its own query. This allows me to effectively pass a selected value from the first subform over to the second subform, via the common parent.
Using the OnClick event of the command button, the code checks the hidden textbox in the main form. If it already holds the value it was going to pass, the hidden textbox is cleared (in other words, the user is deselecting that record). If it doesn't, it passes the value (the user is selecting that record)
The query for the second subform therefore looks something like this :
Code:
SELECT [tbl1].[fld1], [tbl1].[fld2], [tbl2].[fld3]...
FROM [tbl1]
INNER JOIN [tbl2] ON [tbl1].[fld4]=[tbl2].[fld5]...
[COLOR=red]WHERE [tblx].[fldy] = Nz([Forms]![frmMainForm]![txtID],0)[/COLOR]
So if the hidden textbox is empty (no record selected) the query returns an empty dataset (the ID will never be 0) for the second subform. Otherwise, the query returns any records associated with that ID.
Works fine everywhere else I've used this approach
However, with my latest form, I need to use 3 hidden textboxes (this is just the quickest / easiest way given the complexity of the related tables)
Same basic principle though, only difference being that on clicking the command button in the first subform, I pass 3 values to 3 hidden textboxes (one ID and two dates) Or, if the ID is already present (already selected), I clear all 3.
And then the query for the second subform looks like this :
Code:
SELECT [tbl1].[fld1], [tbl1].[fld2], [tbl2].[fld3]...
FROM [tbl1]
INNER JOIN [tbl2] ON [tbl1].[fld4]=[tbl2].[fld5]...
[COLOR=red]WHERE [tblx].[fldy] = Nz([Forms]![frmMainForm]![txtID],0)[/COLOR]
[COLOR=red]AND [tblx].[fldz] >= Nz([Forms]![frmMainForm]![txtDate1],#12/31/1999#)[/COLOR]
[COLOR=red]AND [tblx].[fldz] < Nz([Forms]![frmMainForm]![txtDate2],#01/01/1900#)[/COLOR]
Again, the theory is that if the hidden ID textbox is empty (no record selected) the query returns a blank dataset (the ID will never be 0 and no date can fall in that range) for the second subform. Otherwise, the query returns the records associated with that ID and between those dates.
Here's the problem (finally!!)
The functionality works fine initially. When the form loads, the first subform has records, the second subform is empty (no record selected yet) When I select a record from the first subform, the second subform populates with the correct results associated. When I change my selection in the first subform, the second subform updates accordingly.
But when I deselect from the first subform (and empty all the hidden textboxes) the second subform displays "#Name?" across all the visible controls and after a couple of seconds I get the following error :
Object invalid or no longer set
(I actually get this error several times, with random delays in between, until I close the form)
At this point, selecting / deselecting records in the first subform has no effect, the second subform is basically defunct. If I close the form and reopen it, everything's back to normal again.
I have fairly extensive error handling throughout the DB but it is not firing (i.e. it is not logging the error to my error table) so it's difficult to pinpoint exactly where I need to focus my attention.
What's weird is, I use this method of passing values between subforms via hidden textboxes on the common parent quite a bit and it works seamlessly everywhere else. The only difference I can see here is that I'm passing 3 'hidden' values instead of one?
Can anybody make a suggestion as to what I should be checking?
Thanks & apologies for the long-winded synopsis; if you've made it this far, I thank you for your patience!
Al