Update value in unbound control then trigger event (1 Viewer)

w.forums

New member
Local time
Today, 02:18
Joined
Feb 4, 2015
Messages
4
Hi,

I am updating a value in an unbound control on an unbound form. When the value in the control is changed I want a sequence of code to execute. Specifically changing the record source of a subform and refreshing it.

The problem I have is that when the value of the unbound text box is control is changed (I am using a button to change the value as a test) the after update event on the text box does not do anything.

I did a simple test using a button to change the value in the text box and in the afterupdate event of the text box asked it to output the value of the textbox to a message box as shown below.

The problem is this does not work, nothing happens. If I tab out of the text box or change the value with the keyboard however the msgbox appears. Just not via a vba change.

Any assistance would be greatly appreciated.

Code:
 Private Sub Prod_ID_AfterUpdate()
Dim pid As String
pid = Me.Prod_ID
MsgBox pid
End Sub
  
 Private Sub Button_Test_Click()
Me.Prod_ID.SetFocus
Me.Prod_ID = "TEST"
 End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:18
Joined
Aug 30, 2003
Messages
36,132
As you've found, changing the value in code doesn't trigger the update events. You can call the update event from the other, or create a function and call it from both.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:18
Joined
Feb 28, 2001
Messages
27,313
For anything that says "xxxUPDATE", as pbaldy points out, you must bound to an underlying record because what is being updated is that record. No record? No update. Form_Current has the same problem. No bound record? No Current either.

However, you can always directly call the code for an event if you want to simulate it. If you do, however, you are running a subroutine, not necessarily an event. It would be possible to trigger a RunCode macro function that would call event code, for example. Be warned that if you do this, the "called" event code can be interrupted by "natural" events whereas a "natural" event cannot always interrupt another "natural" event. (They more often get queued up for linear execution.) That is why "DoEvents" exists - to allow such interruptions.
 

w.forums

New member
Local time
Today, 02:18
Joined
Feb 4, 2015
Messages
4
Hi Paul,

Thanks for your reply.

So I should refer to the AfterUpdate event in my vba code.

along the lines of controlname.afterupdate ?

How do I use this syntax?

I'm just looking on the web to learn how.

Thanks
 

w.forums

New member
Local time
Today, 02:18
Joined
Feb 4, 2015
Messages
4
Hi Doc,

Thanks for your reply and to everybody for your patience in explaining this to me. I get confused with the order of how things get processed.

Essential my form which is unbound houses a subform to list all items in an items table. The main form is like a miniswitchboard where a user can view listed items and then view/edit/add etc using buttons. Each item however is linked to a particular product code, so one product can have many items.

What I am trying to achieve is that on an add new product the user goes through a series of forms relating to different aspects of the product, when they get to the add items section it is the main items form with the all items subtable.

As part of the add new product flow the previous form is bound to the products location and on clicking save the form saves and opens the items main form, in this instance however the Product id is placed inside an unbound text box on the unbound form. This all works fine.

What I need to achieve is that the items area filters the items subform to show all items that contain the Product code. I need this to happen whenever the main item form appears and triggers automatically.

I can get it to work with a button so my codes are fine, I am just not understanding how to get it to fire up automatically when the form loads.

The process I was trying is that when the value in the unbound text box is changed (the product id is allocated from the previous form that opens it) the subform record source changes automatically.

Thanks again for everyones kind help.
 

w.forums

New member
Local time
Today, 02:18
Joined
Feb 4, 2015
Messages
4
Hi Doc,

Thanks for your reply and to everybody for your patience in explaining this to me. I get confused with the order of how things get processed.

Essential my form which is unbound houses a subform to list all items in an items table. The main form is like a miniswitchboard where a user can view listed items and then view/edit/add etc using buttons. Each item however is linked to a particular product code, so one product can have many items.

What I am trying to achieve is that on an add new product the user goes through a series of forms relating to different aspects of the product, when they get to the add items section it is the main items form with the all items subtable.

As part of the add new product flow the previous form is bound to the products location and on clicking save the form saves and opens the items main form, in this instance however the Product id is placed inside an unbound text box on the unbound form. This all works fine.

What I need to achieve is that the items area filters the items subform to show all items that contain the Product code. I need this to happen whenever the main item form appears and triggers automatically.

I can get it to work with a button so my codes are fine, I am just not understanding how to get it to fire up automatically when the form loads.

The process I was trying is that when the value in the unbound text box is changed (the product id is allocated from the previous form that opens it) the subform record source changes automatically.

Thanks again for everyones kind help.
 

w.forums

New member
Local time
Today, 02:18
Joined
Feb 4, 2015
Messages
4
Hi All,

Thank you for all of your kind help.

I feel so stupid.

All I need to do is make the code that updates the subform a separate function/procedure and then use the Call name of function in order to manually run the sequence of code.

Thank you once again for all of your help. I obviously misunderstood your responses with the answer staring me right in the face.

Thanks again.

Kind regards & Best wishes
W
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:18
Joined
Aug 30, 2003
Messages
36,132
Happy to help.
 

Users who are viewing this thread

Top Bottom