Show dropdown list when combobox has focus












0















Is it possible to put a single bit of code on an Access form that would automatically show the dropdown list whenever any combobox on the form has focus?



I know I can automatically show the dropdown list whenever a combobox has focus by using the event below. But, if possible, I would prefer to not have to put that line of code on each combobox since I have so many.



Private Sub combobox_GotFocus()
'When the combobox receives focus
'display in drop down position
Me.combobox.Dropdown
End Sub


My database has dozens of forms in it with dozens of comboboxes on each form.










share|improve this question

























  • No, there is not a 'single bit of code' that will accomplish this for all comboboxes. Each will need the event code.

    – June7
    Jan 1 at 18:39













  • Sorry to object but you can

    – Storax
    Jan 1 at 19:09











  • Possible duplicate of Creating a Class to Handle Access Form Control Events

    – Storax
    Jan 1 at 19:10











  • Sorry @Storax but I'm not very good a VBA, I looked at the provided link but I'm not entirely sure where to start.

    – Kevin Kissell
    Jan 1 at 19:23
















0















Is it possible to put a single bit of code on an Access form that would automatically show the dropdown list whenever any combobox on the form has focus?



I know I can automatically show the dropdown list whenever a combobox has focus by using the event below. But, if possible, I would prefer to not have to put that line of code on each combobox since I have so many.



Private Sub combobox_GotFocus()
'When the combobox receives focus
'display in drop down position
Me.combobox.Dropdown
End Sub


My database has dozens of forms in it with dozens of comboboxes on each form.










share|improve this question

























  • No, there is not a 'single bit of code' that will accomplish this for all comboboxes. Each will need the event code.

    – June7
    Jan 1 at 18:39













  • Sorry to object but you can

    – Storax
    Jan 1 at 19:09











  • Possible duplicate of Creating a Class to Handle Access Form Control Events

    – Storax
    Jan 1 at 19:10











  • Sorry @Storax but I'm not very good a VBA, I looked at the provided link but I'm not entirely sure where to start.

    – Kevin Kissell
    Jan 1 at 19:23














0












0








0


1






Is it possible to put a single bit of code on an Access form that would automatically show the dropdown list whenever any combobox on the form has focus?



I know I can automatically show the dropdown list whenever a combobox has focus by using the event below. But, if possible, I would prefer to not have to put that line of code on each combobox since I have so many.



Private Sub combobox_GotFocus()
'When the combobox receives focus
'display in drop down position
Me.combobox.Dropdown
End Sub


My database has dozens of forms in it with dozens of comboboxes on each form.










share|improve this question
















Is it possible to put a single bit of code on an Access form that would automatically show the dropdown list whenever any combobox on the form has focus?



I know I can automatically show the dropdown list whenever a combobox has focus by using the event below. But, if possible, I would prefer to not have to put that line of code on each combobox since I have so many.



Private Sub combobox_GotFocus()
'When the combobox receives focus
'display in drop down position
Me.combobox.Dropdown
End Sub


My database has dozens of forms in it with dozens of comboboxes on each form.







vba ms-access combobox access-vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 18:38









June7

5,18151227




5,18151227










asked Jan 1 at 18:07









Kevin KissellKevin Kissell

72




72













  • No, there is not a 'single bit of code' that will accomplish this for all comboboxes. Each will need the event code.

    – June7
    Jan 1 at 18:39













  • Sorry to object but you can

    – Storax
    Jan 1 at 19:09











  • Possible duplicate of Creating a Class to Handle Access Form Control Events

    – Storax
    Jan 1 at 19:10











  • Sorry @Storax but I'm not very good a VBA, I looked at the provided link but I'm not entirely sure where to start.

    – Kevin Kissell
    Jan 1 at 19:23



















  • No, there is not a 'single bit of code' that will accomplish this for all comboboxes. Each will need the event code.

    – June7
    Jan 1 at 18:39













  • Sorry to object but you can

    – Storax
    Jan 1 at 19:09











  • Possible duplicate of Creating a Class to Handle Access Form Control Events

    – Storax
    Jan 1 at 19:10











  • Sorry @Storax but I'm not very good a VBA, I looked at the provided link but I'm not entirely sure where to start.

    – Kevin Kissell
    Jan 1 at 19:23

















No, there is not a 'single bit of code' that will accomplish this for all comboboxes. Each will need the event code.

– June7
Jan 1 at 18:39







No, there is not a 'single bit of code' that will accomplish this for all comboboxes. Each will need the event code.

– June7
Jan 1 at 18:39















Sorry to object but you can

– Storax
Jan 1 at 19:09





Sorry to object but you can

– Storax
Jan 1 at 19:09













Possible duplicate of Creating a Class to Handle Access Form Control Events

– Storax
Jan 1 at 19:10





Possible duplicate of Creating a Class to Handle Access Form Control Events

– Storax
Jan 1 at 19:10













Sorry @Storax but I'm not very good a VBA, I looked at the provided link but I'm not entirely sure where to start.

– Kevin Kissell
Jan 1 at 19:23





Sorry @Storax but I'm not very good a VBA, I looked at the provided link but I'm not entirely sure where to start.

– Kevin Kissell
Jan 1 at 19:23












1 Answer
1






active

oldest

votes


















0














Create a class named cComboBox



Option Compare Database
Option Explicit

Private WithEvents mComboBox As Access.ComboBox

Private Sub mComboBox_GotFocus()
mComboBox.Dropdown
End Sub

Public Function AddCtl(nCtl As Access.ComboBox) As Access.ComboBox
Set mComboBox = nCtl
mComboBox.OnGotFocus = "[Event Procedure]"
'mComboBox.OnChange = "[Event Procedure]"
Set AddCtl = mComboBox
End Function


and add the following code to your Form



Option Compare Database
Option Explicit

Dim myCBs As New Collection

Private Sub Form_Load()
Dim myCB As cComboBox

Dim ctl As Access.Control
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
Set myCB = New cComboBox
myCB.AddCtl ctl
myCBs.Add myCB
End If
Next

End Sub





share|improve this answer
























  • Thank you so much! That worked beautifully and saved me a ton of time!

    – Kevin Kissell
    Jan 1 at 19:33











  • @Storax; Could you please explain the purpose of the line Set AddCtl = mComboBox in the Function AddCtl() inside the Class cComboBox?

    – Gene
    Jan 1 at 21:03













  • @Gene: No purpose at all, I just copied and modified the code from the link above. So, it is probably better to use a Set property instead. On the other hand it does not do any real harm.

    – Storax
    Jan 2 at 7:29











  • @Storax; No, not that... I just thought it is not needed at all since there is no use for the function's return anyway: it matters not if AddCtl is assigned or not, whatsoever.

    – Gene
    Jan 2 at 16:04











  • @Gene: Right, you could remove the line Set AddCtl = mComboBox completely and everything would still work.

    – Storax
    Jan 2 at 16:15











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997746%2fshow-dropdown-list-when-combobox-has-focus%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Create a class named cComboBox



Option Compare Database
Option Explicit

Private WithEvents mComboBox As Access.ComboBox

Private Sub mComboBox_GotFocus()
mComboBox.Dropdown
End Sub

Public Function AddCtl(nCtl As Access.ComboBox) As Access.ComboBox
Set mComboBox = nCtl
mComboBox.OnGotFocus = "[Event Procedure]"
'mComboBox.OnChange = "[Event Procedure]"
Set AddCtl = mComboBox
End Function


and add the following code to your Form



Option Compare Database
Option Explicit

Dim myCBs As New Collection

Private Sub Form_Load()
Dim myCB As cComboBox

Dim ctl As Access.Control
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
Set myCB = New cComboBox
myCB.AddCtl ctl
myCBs.Add myCB
End If
Next

End Sub





share|improve this answer
























  • Thank you so much! That worked beautifully and saved me a ton of time!

    – Kevin Kissell
    Jan 1 at 19:33











  • @Storax; Could you please explain the purpose of the line Set AddCtl = mComboBox in the Function AddCtl() inside the Class cComboBox?

    – Gene
    Jan 1 at 21:03













  • @Gene: No purpose at all, I just copied and modified the code from the link above. So, it is probably better to use a Set property instead. On the other hand it does not do any real harm.

    – Storax
    Jan 2 at 7:29











  • @Storax; No, not that... I just thought it is not needed at all since there is no use for the function's return anyway: it matters not if AddCtl is assigned or not, whatsoever.

    – Gene
    Jan 2 at 16:04











  • @Gene: Right, you could remove the line Set AddCtl = mComboBox completely and everything would still work.

    – Storax
    Jan 2 at 16:15
















0














Create a class named cComboBox



Option Compare Database
Option Explicit

Private WithEvents mComboBox As Access.ComboBox

Private Sub mComboBox_GotFocus()
mComboBox.Dropdown
End Sub

Public Function AddCtl(nCtl As Access.ComboBox) As Access.ComboBox
Set mComboBox = nCtl
mComboBox.OnGotFocus = "[Event Procedure]"
'mComboBox.OnChange = "[Event Procedure]"
Set AddCtl = mComboBox
End Function


and add the following code to your Form



Option Compare Database
Option Explicit

Dim myCBs As New Collection

Private Sub Form_Load()
Dim myCB As cComboBox

Dim ctl As Access.Control
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
Set myCB = New cComboBox
myCB.AddCtl ctl
myCBs.Add myCB
End If
Next

End Sub





share|improve this answer
























  • Thank you so much! That worked beautifully and saved me a ton of time!

    – Kevin Kissell
    Jan 1 at 19:33











  • @Storax; Could you please explain the purpose of the line Set AddCtl = mComboBox in the Function AddCtl() inside the Class cComboBox?

    – Gene
    Jan 1 at 21:03













  • @Gene: No purpose at all, I just copied and modified the code from the link above. So, it is probably better to use a Set property instead. On the other hand it does not do any real harm.

    – Storax
    Jan 2 at 7:29











  • @Storax; No, not that... I just thought it is not needed at all since there is no use for the function's return anyway: it matters not if AddCtl is assigned or not, whatsoever.

    – Gene
    Jan 2 at 16:04











  • @Gene: Right, you could remove the line Set AddCtl = mComboBox completely and everything would still work.

    – Storax
    Jan 2 at 16:15














0












0








0







Create a class named cComboBox



Option Compare Database
Option Explicit

Private WithEvents mComboBox As Access.ComboBox

Private Sub mComboBox_GotFocus()
mComboBox.Dropdown
End Sub

Public Function AddCtl(nCtl As Access.ComboBox) As Access.ComboBox
Set mComboBox = nCtl
mComboBox.OnGotFocus = "[Event Procedure]"
'mComboBox.OnChange = "[Event Procedure]"
Set AddCtl = mComboBox
End Function


and add the following code to your Form



Option Compare Database
Option Explicit

Dim myCBs As New Collection

Private Sub Form_Load()
Dim myCB As cComboBox

Dim ctl As Access.Control
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
Set myCB = New cComboBox
myCB.AddCtl ctl
myCBs.Add myCB
End If
Next

End Sub





share|improve this answer













Create a class named cComboBox



Option Compare Database
Option Explicit

Private WithEvents mComboBox As Access.ComboBox

Private Sub mComboBox_GotFocus()
mComboBox.Dropdown
End Sub

Public Function AddCtl(nCtl As Access.ComboBox) As Access.ComboBox
Set mComboBox = nCtl
mComboBox.OnGotFocus = "[Event Procedure]"
'mComboBox.OnChange = "[Event Procedure]"
Set AddCtl = mComboBox
End Function


and add the following code to your Form



Option Compare Database
Option Explicit

Dim myCBs As New Collection

Private Sub Form_Load()
Dim myCB As cComboBox

Dim ctl As Access.Control
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
Set myCB = New cComboBox
myCB.AddCtl ctl
myCBs.Add myCB
End If
Next

End Sub






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 1 at 19:25









StoraxStorax

4,2933519




4,2933519













  • Thank you so much! That worked beautifully and saved me a ton of time!

    – Kevin Kissell
    Jan 1 at 19:33











  • @Storax; Could you please explain the purpose of the line Set AddCtl = mComboBox in the Function AddCtl() inside the Class cComboBox?

    – Gene
    Jan 1 at 21:03













  • @Gene: No purpose at all, I just copied and modified the code from the link above. So, it is probably better to use a Set property instead. On the other hand it does not do any real harm.

    – Storax
    Jan 2 at 7:29











  • @Storax; No, not that... I just thought it is not needed at all since there is no use for the function's return anyway: it matters not if AddCtl is assigned or not, whatsoever.

    – Gene
    Jan 2 at 16:04











  • @Gene: Right, you could remove the line Set AddCtl = mComboBox completely and everything would still work.

    – Storax
    Jan 2 at 16:15



















  • Thank you so much! That worked beautifully and saved me a ton of time!

    – Kevin Kissell
    Jan 1 at 19:33











  • @Storax; Could you please explain the purpose of the line Set AddCtl = mComboBox in the Function AddCtl() inside the Class cComboBox?

    – Gene
    Jan 1 at 21:03













  • @Gene: No purpose at all, I just copied and modified the code from the link above. So, it is probably better to use a Set property instead. On the other hand it does not do any real harm.

    – Storax
    Jan 2 at 7:29











  • @Storax; No, not that... I just thought it is not needed at all since there is no use for the function's return anyway: it matters not if AddCtl is assigned or not, whatsoever.

    – Gene
    Jan 2 at 16:04











  • @Gene: Right, you could remove the line Set AddCtl = mComboBox completely and everything would still work.

    – Storax
    Jan 2 at 16:15

















Thank you so much! That worked beautifully and saved me a ton of time!

– Kevin Kissell
Jan 1 at 19:33





Thank you so much! That worked beautifully and saved me a ton of time!

– Kevin Kissell
Jan 1 at 19:33













@Storax; Could you please explain the purpose of the line Set AddCtl = mComboBox in the Function AddCtl() inside the Class cComboBox?

– Gene
Jan 1 at 21:03







@Storax; Could you please explain the purpose of the line Set AddCtl = mComboBox in the Function AddCtl() inside the Class cComboBox?

– Gene
Jan 1 at 21:03















@Gene: No purpose at all, I just copied and modified the code from the link above. So, it is probably better to use a Set property instead. On the other hand it does not do any real harm.

– Storax
Jan 2 at 7:29





@Gene: No purpose at all, I just copied and modified the code from the link above. So, it is probably better to use a Set property instead. On the other hand it does not do any real harm.

– Storax
Jan 2 at 7:29













@Storax; No, not that... I just thought it is not needed at all since there is no use for the function's return anyway: it matters not if AddCtl is assigned or not, whatsoever.

– Gene
Jan 2 at 16:04





@Storax; No, not that... I just thought it is not needed at all since there is no use for the function's return anyway: it matters not if AddCtl is assigned or not, whatsoever.

– Gene
Jan 2 at 16:04













@Gene: Right, you could remove the line Set AddCtl = mComboBox completely and everything would still work.

– Storax
Jan 2 at 16:15





@Gene: Right, you could remove the line Set AddCtl = mComboBox completely and everything would still work.

– Storax
Jan 2 at 16:15




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997746%2fshow-dropdown-list-when-combobox-has-focus%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]