Solved Afterupdate with no update. (3 Viewers)

John Sh

Active member
Local time
Today, 15:06
Joined
Feb 8, 2021
Messages
665
This is probably a dumb question, but
I have a combo box that gets focus with the correct data.
When I click on the combo box there is no response from the "afterupdate" or "onclick" events.
How do I get focus to move to the next control?
 
Try the following line of code in the After Update event of the combo:

DoCmd.GoToControl "[NameOfYourControl]"
 
Last edited:
When I click on the combo box there is no response from the "afterupdate" or "onclick" events.
I think when you change something in the combo and press Enter key, the Default behavior is to stay on the combo.
unlike in the Textbox, when you press Enter key, you go to next Textbox/record.
 
Arnel, when I press Enter in a combobox, cursor moves to next control, even after changing value.

Combobox does not have an EnterKeyBehavior property which means this action cannot be altered like with textbox.

AfterUpdate and Click events work just fine for me.

If you want to provide db for analysis, follow instructions at bottom of my post.
 
Last edited:
Thank you all.
I finished up using the mouseup event.
Obviously the mouse down event works equally well but feels a bit too instantaneous.
John
 
That didn't work because the focus changes when you release the mouse button on the dropdown arrow.
You don't get to see the dropdown or select an item.
 
Perhaps clarify what you are trying to do and how - seems like your issue is when clicking on the combo down arrow?

And the after update on fires if the selection changes
 
That didn't work because the focus changes when you release the mouse button on the dropdown arrow.
You don't get to see the dropdown or select an item.

That's to be expected. If you want to trigger the AfterUpdate event procedure in a situation where the control's value is already the one you want, then you would either have to drop down the list and select the value again, or type the value again into the control without dropping down the list. However, why, in this situation can't you just tab out of the control to the next control in the tab order?
 
That's to be expected. If you want to trigger the AfterUpdate event procedure in a situation where the control's value is already the one you want, then you would either have to drop down the list and select the value again, or type the value again into the control without dropping down the list. However, why, in this situation can't you just tab out of the control to the next control in the tab order?
Hi Ken.
That is the simplest method but we're not working with people who are very adaptable.
They will click on every control and expect it to go to the next.
I have actually taught them to not use tab because the tab order is not always the next control.
Some of the forms have 90 odd controls and putting them in sequential tab order is a bridge too far.
 
Some of the forms have 90 odd controls and putting them in sequential tab order is a bridge too far.

I would presume from that statement that the controls are not placed so that using the Tab "Auto-Order" option would help.
 
I would presume from that statement that the controls are not placed so that using the Tab "Auto-Order" option would help.
NO, Doc_man.
The controls are placed top to bottom and the auto tab goes left to right.
I have solved the problem using the gotfocus event

Code:
Private Sub cboFlower_GotFocus()
    Me.cboFlower.BackColor = TempVars!colouron
    If Nz(Me.cboFlower.ItemData(0), "") = "" Or Nz(Me.cboFlower, "") > "" Then
        Me.cboCommon.SetFocus
    ElseIf Nz(Me.cboFlower.ItemData(1), "") > "" Then
        Me.cboFlower.Dropdown
    Else
        Me.cboFlower = Me.cboFlower.ItemData(0)
        Me.cboCommon.SetFocus
    End If
End Sub

This bypasses the control if it already has data or there is nothing in the dropdown.
If there is only one result from the query it is entered and the focus moves on.
If there is more than one result then the dropdown appears and the after update event is triggered after a selection is made.

I'll put this into a sub so it can be called from where ever.
John
 
FWIW, here is the sub.

Called from the current control's gotfocus event with "isanythingthere me, me.nameofnextcontrol"

Code:
Public Sub isAnyThingThere(frm As Form, ctlNext As Control)
    Dim ctl As Control
    Set ctl = frm.ActiveControl
    With frm
        .Controls(ctl.Name).BackColor = TempVars!colouron
        If Nz(.Controls(ctl.Name).ItemData(0), "") = "" Or Nz(.Controls(ctl.Name), "") > "" Then
            .Controls(ctlNext.Name).SetFocus
        ElseIf Nz(.Controls(ctl.Name).ItemData(1), "") > "" Then
            .Controls(ctl.Name).Dropdown
        Else
            .Controls(ctl.Name) = .Controls(ctl.Name).ItemData(0)
            .Controls(ctlNext.Name).SetFocus
        End If
    End With
    Set frm = Nothing
    Set ctl = Nothing
    Set ctlNext = Nothing
End Sub

Thanks to all for your input.
John
 
I have actually taught them to not use tab because the tab order is not always the next control.
Some of the forms have 90 odd controls and putting them in sequential tab order is a bridge too far.
Haha! So, instead of spending 15 minutes setting the tab order you've wasted 24 hours trying to code a solution that breaks anyone's natural muscle memory for navigating between fields!

Just want to make sure that you are aware that you can arrange tab order using drag and drop, not just by manually entering the actual number in the Tab Order property field?
 
This thread veers towards a practice that I am all too familiar with, and which I now try to avoid as much as I possibly can.

That is, trying to put wads of code into multiple form and control events in order to bypass, or to overcome, or to counteract, or to outwit normal Access behaviors.

I came to this position through my own experiences. I recall one particular pit I dug for myself (and by extension, the client), in which I was writing line after line of code to try to control input and data validation, along with interface display options for what should have been a fairly straightforward scenario. Each new attempt to control some event led to additional unwanted side effects that had to be addressed with yet another layer of code. Finally, in desperation, I started over and let Access standard behaviors do as much of the work as possible, keeping my interventions as light as possible. Faster, more reliable data input soon reappeared. I was able to move to more pressing matters, and also to remove wads of superfluous code. It became what is sometimes referred to as a learning moment for me.

My point is this, asking the control -- a combo box in this instance -- to behave differently from how it was designed by Microsoft may not be the best strategy. Rather than writing code to set focus elsewhere when the user clicks it (which I also question as a strategy anyway), I suggest stepping back and rethinking why you came to the conclusion you needed to override the standard Access behavior in the first place.

What problem is being resolved here? If it is, as you say, a matter of users expecting non-standard behavior, a conversation about expectations and reality might go a long way. If they convince you that a) their work will go faster and more efficiently, or b) that it will avoid common errors or c) they'll like you better, well, maybe it's worth trying to wrestle Access for control of its interface.

An aside into AI might be instructive here as well.

One of the key conditions for successful use of AI is that you must assume the role of Project Manager. When Chatty or Claude or Grok spits out a chunk of code, you can't simply accept it, copy and paste it into your application and move on. You have to evaluate that code for accuracy and fit for purpose. That same responsibility is yours when working with users. Either you are the Project Manager, or the users are a diffuse committee of pseudo project managers. When it comes time to evaluate a solution for accuracy and fit for purpose, "Because we want it that way" is not a valid criteria. (I have a granddaughter who thinks it is, but she's only 3 years old.) Their desires are valuable input into YOUR evaluation, of course. It's just not the final word.

I apologize for the length of this post and the lecture it became.
 
Some of the forms have 90 odd controls and putting them in sequential tab order is a bridge too far.

I don't know about anyone else but 90 controls on a single form would i.m.o. be pain full to work with. My worst form has maybe 40 including columns for a sub form; most of the other controls are for lookup.
 
I can't add more to Geroge's wonderful post above. After all these years, 9 out of 10 times, when you try to change or fight the default behavior(s) of Access? It tends to be a bad idea.....

This is probably a dumb question, but
I have a combo box that gets focus with the correct data.
When I click on the combo box there is no response from the "afterupdate" or "onclick" events.
How do I get focus to move to the next control?
Simply use the Change event. This one:

1764631350527.png


and then the code in that on changed event:
Code:
Private Sub Combo161_Change()
    
    DoCmd.GoToControl "FirstName"
    
    
End Sub

R
Albert
 
asking [Access] to behave differently from how it was designed by Microsoft may not be the best strategy.

Back in 2005 I approached an experienced VB6 developer named Tom Kiehl about converting an application developed with Oracle Professional 6 for MS-DOS to Access 2003. Tom said he disliked Access because it does not provide granular control of several features and you cannot override their default behaviour, unless the feature provides the options you need. Tom said he had an extensive library of vb6 functions which he could customize and rapidly build applications. I almost went the VB6 route, but at that time mainstream support for VB6 IDE had just ended and sunsetting in 2008. However, the VB6 runtime still runs apps on Windows 10 and 11 even though the tools are no longer supported.
 

Users who are viewing this thread

Back
Top Bottom