Solved How to open combo box when form loads (1 Viewer)

DataAmatuer

New member
Local time
Today, 01:29
Joined
Feb 15, 2021
Messages
16
I seldom use the timer event because I find it causes problems. I also recall that when I first started programming the general consensus was not to use the Timer. I have no idea what the latest advice is.
It turned out that the combo box would STILL close sometimes even when I commented-out the On Timer event and had the On Load event call the Public Sub Dropdown(), which used the ".Dropdown" command. Since discovering that there were still inexplicable cases of the combo box not staying open, I commented-out the ".Dropdown" command and replaced it with a SendKeys statment that effectively keys in F4, which is the keyboard shortcut to open a combo box. This seems to work (but because if the intermittent nature of the problem, I'm not yet confident that it will keep on working!). Here's the code now:
Code:
Public Sub Dropdown()
'   Me.cboCkInsCo.Dropdown
   SendKeys "{F4}"
   DoEvents
  
End Sub
 

isladogs

MVP / VIP
Local time
Today, 08:29
Joined
Jan 14, 2017
Messages
18,207
As you may already know, SendKeys is very unreliable and not recommended for various reasons
Much better to stick with the timer, which AFAIK will work reliably.
I don't know of any reason why timer events would not be recommended
 

DataAmatuer

New member
Local time
Today, 01:29
Joined
Feb 15, 2021
Messages
16
As you may already know, SendKeys is very unreliable and not recommended for various reasons
Much better to stick with the timer, which AFAIK will work reliably.
I don't know of any reason why timer events would not be recommended
I did not know that about SendKeys. Thank you for alerting me. But, as Uncle Gizmo posted a little while ago, the On Timer event is also reputed to cause problems. In my case, when I put the combo box ".Dropdown" command in a timer event, the box WOULD dropdown, but then close after just a few moments. Furthermore, it wasn't consistent. Sometimes the form would load and the box would dropdown and stay open. Other times it wouldn't. So far, the SendKeys statement seems to be working and keeping the box open (i.,e., dropped down).
 

isladogs

MVP / VIP
Local time
Today, 08:29
Joined
Jan 14, 2017
Messages
18,207
UG made that comment but didn't provide any concrete evidence to back it up. If there are problems, I've never experienced them.

i thought you stated that adding the line DoEvents made it work reliably for you as indeed it did for me.
In my experience, the dropdown persists until you click anywhere else on the form
 

DataAmatuer

New member
Local time
Today, 01:29
Joined
Feb 15, 2021
Messages
16
UG made that comment but didn't provide any concrete evidence to back it up. If there are problems, I've never experienced them.

i thought you stated that adding the line DoEvents made it work reliably for you as indeed it did for me.
In my experience, the dropdown persists until you click anywhere else on the form
You are correct, I did say yesterday that the DoEvents line made the combo box stay open when the form loaded. And it did . . . for a while. But then later the combo box resumed this strange behavior on only staying open a few moments after the form opened then closing (without me having clicked anywhere else). It's a mystery to me. Sometimes I will edit some other part of the code for the form, reopen it to test it, and then the combo box opens and stays open, even though the code that I edited had nothing to do with the combo box. Then I'll close everything and later reopen it, and once again the combo box will not stay open. I have to manually open it with dropdown arrow or the F4 key. So far, the SendKeys "{F4}" statement hasn't failed a single time to leave the box open when the form loads.

I don't know why the On Timer works for you and doesn't for me. Maybe I have some code in the Class Module for the form that is causing the problem.

In any case, thank you again for staying with me on this. BTW, I like your signature line about failing and asking for help. I've saved a copy of it.
 

isladogs

MVP / VIP
Local time
Today, 08:29
Joined
Jan 14, 2017
Messages
18,207
BTW, I like your signature line about failing and asking for help. I've saved a copy of it.
Its actually two quotes from different sources that I thought went well together....

BTW when you tried the timer code, did you remember to add the line Me.TimerInterval=0 at the end so the code only ran once
 
Last edited:

DataAmatuer

New member
Local time
Today, 01:29
Joined
Feb 15, 2021
Messages
16
Its actually two quotes from different sources that I thought went well together....

BTW when you tried the timer code, did you remember to add the line Me.TimerInterval=0 at the end so the code only ran once
Yes. I did try that. In fact that's the way I first had it when it started leaving the combo box opened only briefly. There's more that I have discovered about this problem that is related to the code in the AfterUpdate event, but I'm out of time for now. Maybe I can tell you more about this tomorrow, if you're interested.
 

DataAmatuer

New member
Local time
Today, 01:29
Joined
Feb 15, 2021
Messages
16
Its actually two quotes from different sources that I thought went well together....

BTW when you tried the timer code, did you remember to add the line Me.TimerInterval=0 at the end so the code only ran once
Let me follow up on this problem about the combo box that sometimes would stay open after opening the form, and other times not stay open. I had about decided that my form had a split personality disorder. But, alas, it now appears that the problem was a loose nut between the chair and the computer keyboard! 😄

I had created the form by copying a similar form and pasting it in with a new name. There were controls on the copied form that I did not need in the pasted version, so I deleted them. What I did not do was delete the sub procedures that were related to those deleted controls, thus leaving them "orphaned" in VBA. It appears that this explains why my combo box would first open (as instructed to do by either an On Timer event or a Public Sub using the ".Dropdown" command), but then moments later it would close. I suspect that Access would try to execute these orphaned sub procedures and that this would take the focus off of the combo box and cause it to close. When I commented-out these orphaned sub procedures, the split personality of the form was apparently cured.

Let me again say thank you to Isladogs, Uncle Gizmo, and theDBguy for all the very helpful suggestions. And also to Mike Krailo for questioning the wisdom of what I was trying to do.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:29
Joined
Oct 29, 2018
Messages
21,447
Hi. Congratulations on sorting it out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom