Events do not fire when assigning a value to a control using vba

P

Pete

Access 2003 (Access 2000 format)
I have a subform (on a main form) which contains a subform. When the user
goes to a new record and clicks a button on the main subform to select a
photo, the button code assigns the path & filename to a textbox (which is
then displayed in an Image Control) and then sets the focus to a combo box on
it's subform for the user to enter 1 or more categories associated with the
selected photo. But, the focus comes back to the button on the parent subform
and because I have programmatically set the value of the textbox on the
parent subform, none of the events fire.
Is this normal?
I have set Referential Integrity throughout but the app allows the user to
move off the record without at least 1 category being assigned.

I can make available the whole mdb app for clarity, as this only contains a
small amount of test data. The only requirement is that you will need some
bmp or jpegs for testing.
Any comments will be greatly appreciated.
Many thanks.
 
D

Dirk Goldgar

Pete said:
Access 2003 (Access 2000 format)
I have a subform (on a main form) which contains a subform. When the user
goes to a new record and clicks a button on the main subform to select a
photo, the button code assigns the path & filename to a textbox (which is
then displayed in an Image Control) and then sets the focus to a combo box
on
it's subform for the user to enter 1 or more categories associated with
the
selected photo. But, the focus comes back to the button on the parent
subform
and because I have programmatically set the value of the textbox on the
parent subform, none of the events fire.
Is this normal?

Yes. Controls' data-update events don't fire when value assignments are
made via code. But since your code "knows" that it is updating the
control's value, it can call the event procedure directly; e.g.,

Me!MyTextBox = "something"
Call MyTextBox_AfterUpdate
I have set Referential Integrity throughout but the app allows the user to
move off the record without at least 1 category being assigned.

I don't have a good enough picture of your setup to know how to address this
issue. Note, though, that referential integrity ensures that a foreign key
value, if specified, is valid. It does not, however, require that a foreign
key value be specified, so the foreign key field could be Null. To make the
foreign key field be required, you can set the field's Required property in
the table design.
 
P

Pete

Thanks for the reply Dirk.

The main subform(#1) has a PK of PhotoID. The subform on #1 (#2), has a
compound PK of PhotoID & CategoryID. These are the only 2 fields in the
junction table which is the recordsource for #2. So #2 sits between Photo and
Categories tables, which I have called tblAssignedCategories.

I am trying to stop the user moving off the record when a photo is assigned
to subform #1, but no category is assigned to #2. I have tried calling the
BeforeUpdate event of the form and setting Cancel = True, in the button code
which handles the photo selection, but if the user moves off the record,
access displays a message, but still moves off the record.

Hope this clarifies the situation.
 
P

Pete

Tried a different tack - now working.

I am still using the same subform setup, but am disabling the navigation
buttons and manually checking if there are any related records in the
junction table in the close button's Click event. If there aren't any, I am
manually calling the before update of the form, displaying an appropriate
message, and setting Cancel = True.

The app now pauses for required data.
Many thanks for all your comments - especially you Marsh!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top