Show dropdown list when combobox has focus
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
add a comment |
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
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
add a comment |
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
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
vba ms-access combobox access-vba
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
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 lineSet AddCtl = mComboBox
in theFunction AddCtl()
inside the ClasscComboBox
?
– 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 ifAddCtl
is assigned or not, whatsoever.
– Gene
Jan 2 at 16:04
@Gene: Right, you could remove the lineSet AddCtl = mComboBox
completely and everything would still work.
– Storax
Jan 2 at 16:15
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 lineSet AddCtl = mComboBox
in theFunction AddCtl()
inside the ClasscComboBox
?
– 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 ifAddCtl
is assigned or not, whatsoever.
– Gene
Jan 2 at 16:04
@Gene: Right, you could remove the lineSet AddCtl = mComboBox
completely and everything would still work.
– Storax
Jan 2 at 16:15
add a comment |
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
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 lineSet AddCtl = mComboBox
in theFunction AddCtl()
inside the ClasscComboBox
?
– 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 ifAddCtl
is assigned or not, whatsoever.
– Gene
Jan 2 at 16:04
@Gene: Right, you could remove the lineSet AddCtl = mComboBox
completely and everything would still work.
– Storax
Jan 2 at 16:15
add a comment |
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
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
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 lineSet AddCtl = mComboBox
in theFunction AddCtl()
inside the ClasscComboBox
?
– 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 ifAddCtl
is assigned or not, whatsoever.
– Gene
Jan 2 at 16:04
@Gene: Right, you could remove the lineSet AddCtl = mComboBox
completely and everything would still work.
– Storax
Jan 2 at 16:15
add a comment |
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 lineSet AddCtl = mComboBox
in theFunction AddCtl()
inside the ClasscComboBox
?
– 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 ifAddCtl
is assigned or not, whatsoever.
– Gene
Jan 2 at 16:04
@Gene: Right, you could remove the lineSet 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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