Full Version: Combobox-value From External Form And Fire The Combo By VBA
UtterAccess Forums > Microsoft® Access > Access Forms
Caesar55
Hello

I am a very newbie trying to build a database to handle main machanical drawings data (customer, drawing number, drawing index etc.)

In a form named "RiepilogoDisegni" based on a query I have one combo from which I can select the pertinet values and see the related data. This Combo is named "CasellaCombinata44".
Once a value is selected here,I would pass a value from the recordset, that comes in the textbox named "IDarticolo", to a combo named "CasellaCombinata8" located in another form named "Base_EditaValori" and use it as the selected value for this combo.

Given that "Casella Combinata8" works properly by clickig on the arrow and selecting a value, in the AfterUpdate event of "CasellaCombinata44" (frm "RiepilogoDisegni") is:

Private Sub CasellaCombinata44_AfterUpdate()
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Numdisegno] = '" & Me![CasellaCombinata44] & "'"
Me.Bookmark = rs.Bookmark


Forms!Base_EditaValori!CasellaCombinata8 = Me![IDarticolo]

Forms!Base_EditaValori.SetFocus
Forms!Base_EditaValori!CasellaCombinata8.Requery
Forms!Base_EditaValori!CasellaCombinata8.SetFocus
Forms!Base_EditaValori!CasellaCombinata8.Dropdown

Making a choice in "CasellaCombinata44" I can see actually the same value in "CasellaCombinata8", the combo dropdwn and highlighted but, the recordset in the frm "Base_EditaValori" is not updated at all.
If I exit from the combo (by TAB) or in any case once the combo has lost the focus,I am expecting that the frm will be updated but it doesn't happen.

If I make click on the combo, as it is normally done, the frm is then correctly updated.

What am I doing wrong so that the frm be automatically updated once the combo receives the value from the "CasellaCombinata44"?

I imagine it is a very simple problem and that the solution is in front of me but my poor knowledge is preventing to see it.
Thanks in advance to anyone that would help me.
dmhzx
It looks as though you haven't asked the form to change, just the combo.


Forms!Base_EditaValori!CasellaCombinata8

how about trying

Forms!Base_EditaValori.findfirst --- whatever?
tina t
QUOTE
Making a choice in "CasellaCombinata44" I can see actually the same value in "CasellaCombinata8", the combo dropdwn and highlighted but, the recordset in the frm "Base_EditaValori" is not updated at all.
If I exit from the combo (by TAB) or in any case once the combo has lost the focus,I am expecting that the frm will be updated but it doesn't happen.

what do you mean by "updated"? what do you expect or want to happen?

QUOTE
If I make click on the combo, as it is normally done, the frm is then correctly updated.

again, we need to know what "updated" means. is there code running in the AfterUpdate event of CasellaCombinata8?

you need to give us more details, pls, so we can help you troubleshoot.

hth
tina
Caesar55
Hello Tina
sorry to be not clear enough . Togheter with VBA inexperience I have also a language problem iconfused.gif

Let me try:
by "updated" I mean that once the "CasellaCombinata8" shows the value that has received from the other form and that, obviously, is in the combo list, I would see that all the controls in the form show the values pertinet the record identified by the combo.
Practically I would have automatically what happens in a "normal" use of a combo; by clicking on the side arrow, selecting a value and making a click the controls in the form will show the new related values.

Currently even if I get the new wanted value in the "CasellaCombinata8" , after that, nothing happens. All the controlls in the form, report the precedindg values (referred to the previous value in the combo).
To see the new true values (form update), related to the combo value, I must do the click on the arrow and confirm by a click the already highligthed value of the combo like I normally do with combos.
How to "jump" the clicks?

Once again sorry if it is confused.

Caesar55
azolder
I assume you have an AfterUpdate event procedure for CasellaCombinata8. I believe setting a value in a control using VBA will not trigger the control's after update event.

Try declaring the CasellaCombinata8_AfterUpdate as a public procedure then call it from RiepilogoDisegni:
CODE
Forms!Base_EditaValori!CasellaCombinata8 = Me![IDarticolo]
Forms!Base_EditaValori!CasellaCombinata8.AfterUpdate
Caesar55
Hi azolder
thank you for your reply.
It is right; there is an AfterUpdate event procedure for CasellaCombinata8.

I have declared CasellaCombinata8_AfterUpdate as public and then call it as you have indicated.
Unfortunately I now get:
Run-Time error '438': Object doesn't support property or method
azolder
Did you change the Private to Public in the declaration?
CODE
Public Sub CasellaCombinata8_AfterUpdate()

Other than that, I can't help much without at least knowing the code in CasellaCombinata8_AfterUpdate . Better yet, uploading a sanitized version (no sensitive data) of you database would be even more help.
Caesar55
I did a module declaring exactly what you have written.


Here the code of CasellaCombinata8_AfterUpdate()

Private Sub CasellaCombinata8_AfterUpdate()
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[IDarticolo] = '" & Me![CasellaCombinata8] & "'"
Me.Bookmark = rs.Bookmark

End Sub
azolder
We're not talking a standard module, we talking the form Base_EditaValori module:

Public Sub CasellaCombinata8_AfterUpdate()
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[IDarticolo] = '" & Me![CasellaCombinata8] & "'"
Me.Bookmark = rs.Bookmark

End Sub
Caesar55
Ooops!
Sorry to have misunderstood your recommendation.
I have changed as required but Run-Time error '438': Object doesn't support property or method still comes up.

Then I have recognized that, as per previous post, in RiepilogoDisegni we have:
Forms!Base_EditaValori!CasellaCombinata8 = Me![IDarticolo]
Forms!Base_EditaValori!CasellaCombinata8.AfterUpdate
I have changed this last row as:
Forms!Base_EditaValori.CasellaCombinata8_AfterUpdate
and...it works!!

Thank you really very much for your help hat_tip.gif thumbup.gif
Have a nice day!

Caesar55
azolder
QUOTE
Forms!Base_EditaValori!CasellaCombinata8.AfterUpdate
Opps. My bad. Sorry.big_grin.gif
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.