|
-
May 3rd, 2005, 12:27 PM
#1
Thread Starter
New Member
Clear combo box selection
I have a form built to enter certain text into a Word document based upon values in a combo box drop-down list. My problem is that I can't figure out how to clear my selection if I inadvertently select a value I shouldn't have. For example:
Combo box has choices of Left and Right. I select left when in fact I shouldn't have selected anything at all. Now I have no way to get rid of it. What I'd like to happen is if I press the Delete key it clears out the selection I just made. Is that possible? If so, how do I do it?
Thanks,
Mario64
-
May 3rd, 2005, 12:32 PM
#2
Re: Clear combo box selection
Welcome to the Forums.
Are you using a UserForm or automating Word from VB?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 3rd, 2005, 12:33 PM
#3
Thread Starter
New Member
Re: Clear combo box selection
 Originally Posted by RobDog888
Welcome to the Forums.
Are you using a UserForm or automating Word from VB?
UserForm
Mario64
-
May 3rd, 2005, 12:41 PM
#4
Re: Clear combo box selection
Set the Style property of the combo to 0 - fmStyleDropDownCombo so you can delete the text that is typed in. Or Add
an item that is an empty string. Then if they select "blank" it can blank out or do what ever you code it to do.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 3rd, 2005, 12:44 PM
#5
Thread Starter
New Member
Re: Clear combo box selection
 Originally Posted by RobDog888
Set the Style property of the combo to 0 - fmStyleDropDownCombo so you can delete the text that is typed in. Or Add
an item that is an empty string. Then if they select "blank" it can blank out or do what ever you code it to do.
I actually chose not to use that style because I want to force a selection from the drop-down list only. So I'm using style 2.
Is there another way to force selection from the combo box while allowing Delete to work?
Thanks,
Mario64
-
May 3rd, 2005, 12:55 PM
#6
Re: Clear combo box selection
Yes, you can set the .ListIndex to -1 or no selection. In your clear button click event you can do this.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 3rd, 2005, 12:59 PM
#7
Thread Starter
New Member
Re: Clear combo box selection
 Originally Posted by RobDog888
Yes, you can set the .ListIndex to -1 or no selection. In your clear button click event you can do this.
Hmm, let me try that and I'll report back. Tx.
Mario64
-
May 3rd, 2005, 01:03 PM
#8
Thread Starter
New Member
Re: Clear combo box selection
Can't seem to get it to work. I changed the style back to 0 then added the following:
Private Sub UserForm_Initialize()
' In this section of our code, we will set up the values
' for all of the combo boxes.
' We need to set up the data for our combo boxes
' Choices for Side Indicator
cmbSideInd.ListIndex = -1
cmbSideInd.AddItem ("L Left")
cmbSideInd.AddItem ("R Right")
cmbSideInd.AddItem ("B Both")
It still allows me to "free text" an entry into the box. What am I doing wrong?
Mario64
-
May 3rd, 2005, 01:15 PM
#9
Re: Clear combo box selection
Keep the Style set to 0.
Then after all items are added, then try the -1.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 4th, 2005, 08:09 AM
#10
Thread Starter
New Member
Re: Clear combo box selection
 Originally Posted by RobDog888
Keep the Style set to 0.
Then after all items are added, then try the -1.
Nope. Still didn't work unfortunately. They can type anything they want into the box and it will accept it.
Mario64
-
May 4th, 2005, 12:44 PM
#11
Thread Starter
New Member
Re: Clear combo box selection
Ok. I'm getting close. Using this code
Private Sub cmbSideInd_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 46 Then cmbSideInd.Clear
End Sub
does clear the box but then if you click the drop down again the whole thing is blank. I want to clear out the user's selection NOT the drop down list itself. Any ideas on how to accomplish that?
Thanks,
Mario64
-
May 4th, 2005, 12:55 PM
#12
Re: Clear combo box selection
.Clear will actually remove all list entrires from the combo box.
In the properties window for the combo box set the Style to 2. then add this code as a test but name your obejcts as the same so the events fire.
VB Code:
Private Sub CommandButton2_Click()
ComboBox1.ListIndex = -1
End Sub
Private Sub UserForm_Initialize()
ComboBox1.AddItem "Test1"
ComboBox1.AddItem "Test2"
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 4th, 2005, 01:31 PM
#13
Thread Starter
New Member
Re: Clear combo box selection
Yeah, that did it. Thanks!
One last question, what's the difference between the Click event and the KeyDown event? I'm a keyboard person and won't actually be using the mouse to select from the combo boxes. Will Click still work? Should I take into account both scenarios?
Thanks,
Mario64
-
May 4th, 2005, 01:43 PM
#14
Re: Clear combo box selection
 Originally Posted by mario64
Yeah, that did it. Thanks!
One last question, what's the difference between the Click event and the KeyDown event? I'm a keyboard person and won't actually be using the mouse to select from the combo boxes. Will Click still work? Should I take into account both scenarios?
Thanks,
Mario64
Yes...in fact you should always give your users two or three different ways of doing the same thing. They like that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|