D
David W. Fenton
I have noticed over the years that when you use a datasheet subform
with a combo box list for the user to create a record in the join
table for a many-to-many relationship, users do not understand that
they are creating a record in a table (nor should they need to do
so).
This causes a problem in this scenario:
1. user lands in a new row.
2. user picks something from the list.
3. user changes mind and deletes text in combo box.
4. when the form updates, they get either of these two errors:
3058 Index or primary key can't contain a Null value.
3162 You tried to assign the Null value to a variable that
isn't a Variant data type.
The other scenario that is equivalent:
1. users sees a list of items in the subform.
2. user wants to remove one item from the list.
3. users deletes the text in the combo box for that row.
4. one of the above error messages pops up.
So far as I can tell, neither of these errors is trappable via the
events of the combo box control or the form, because they are
happening at the database engine level (it's an RI or index error,
depending on your schema), and as long as the combo boxes are bound
(which they must be to display correct data), the database engine
validation happens before the control and form events have a chance
to be activated.
The lack of trappability of errors like this in bound controls is
one of the reasons I've always avoided validation rules in field
definitions, since it causes the same problem, an untrappable error
(so far as I'm aware).
Is there some way to trap it after all of which I'm just ignorant?
What I'd like to do in trapping the error is ask the user if they'd
like to delete that item from the BROOMSTICK list (where BROOMSTICK
is the meaningful name they have for the items listed in the
subform, as opposed to the list of items in the combo box). I've
Googled this and find that others have encountered the problem, but
nobody seems to have a workaround.
If there is no workaround, I see these two options:
1. train the users to do it right.
2. revise the UI for entering these items so that it avoids this.
While #1 will be successful with the user population I'm working
with in the app I'm working on right now, it goes against my grain,
as I hate handling an anticipated error by training the users how to
avoid it, instead of changing the app so that the user can't make
the mistake. I think the user interpretation of what should work is
reasonable, and training them to avoid it is an example of Joel
Spolsky's rule of leaky abstractions
(http://www.joelonsoftware.com/articles/LeakyAbstractions.html),
where the UI is allowing the underlying implementation to leak
through to the user interaction layer.
But #2 is problematic in that I've already got limited screen real
estate -- that's the reason I was using a datasheet subform in the
first place. Sure, editing could be restricted to a popup form, but
I hate popup forms for things that should be doable in place.
Any suggestions, either in how to avoid it or how to trap it?
The current app is in A2003, though that likely doesn't matter as
this has been an issue in every version of Access I've ever used
(which is all of them from Access 2 on, except 2007).
with a combo box list for the user to create a record in the join
table for a many-to-many relationship, users do not understand that
they are creating a record in a table (nor should they need to do
so).
This causes a problem in this scenario:
1. user lands in a new row.
2. user picks something from the list.
3. user changes mind and deletes text in combo box.
4. when the form updates, they get either of these two errors:
3058 Index or primary key can't contain a Null value.
3162 You tried to assign the Null value to a variable that
isn't a Variant data type.
The other scenario that is equivalent:
1. users sees a list of items in the subform.
2. user wants to remove one item from the list.
3. users deletes the text in the combo box for that row.
4. one of the above error messages pops up.
So far as I can tell, neither of these errors is trappable via the
events of the combo box control or the form, because they are
happening at the database engine level (it's an RI or index error,
depending on your schema), and as long as the combo boxes are bound
(which they must be to display correct data), the database engine
validation happens before the control and form events have a chance
to be activated.
The lack of trappability of errors like this in bound controls is
one of the reasons I've always avoided validation rules in field
definitions, since it causes the same problem, an untrappable error
(so far as I'm aware).
Is there some way to trap it after all of which I'm just ignorant?
What I'd like to do in trapping the error is ask the user if they'd
like to delete that item from the BROOMSTICK list (where BROOMSTICK
is the meaningful name they have for the items listed in the
subform, as opposed to the list of items in the combo box). I've
Googled this and find that others have encountered the problem, but
nobody seems to have a workaround.
If there is no workaround, I see these two options:
1. train the users to do it right.
2. revise the UI for entering these items so that it avoids this.
While #1 will be successful with the user population I'm working
with in the app I'm working on right now, it goes against my grain,
as I hate handling an anticipated error by training the users how to
avoid it, instead of changing the app so that the user can't make
the mistake. I think the user interpretation of what should work is
reasonable, and training them to avoid it is an example of Joel
Spolsky's rule of leaky abstractions
(http://www.joelonsoftware.com/articles/LeakyAbstractions.html),
where the UI is allowing the underlying implementation to leak
through to the user interaction layer.
But #2 is problematic in that I've already got limited screen real
estate -- that's the reason I was using a datasheet subform in the
first place. Sure, editing could be restricted to a popup form, but
I hate popup forms for things that should be doable in place.
Any suggestions, either in how to avoid it or how to trap it?
The current app is in A2003, though that likely doesn't matter as
this has been an issue in every version of Access I've ever used
(which is all of them from Access 2 on, except 2007).