PC Review


Reply
Thread Tools Rate Thread

ComboBox displays last selection

 
 
PW
Guest
Posts: n/a
 
      23rd Jul 2008
I have a combo box on a user form. The first time I run it, it works fine.
The second time I run it. It has the previous selection in it. How can I
have it come up blank?

Thank You,

PW
 
Reply With Quote
 
 
 
 
brzak
Guest
Posts: n/a
 
      23rd Jul 2008
Make use of teh ListIndex property

From VBA Help:
"Values of ListIndex range from –1 to one less than the total number
of rows in a list (that is, ListCount – 1). When no rows are selected,
ListIndex returns –1"

so at whicever event you want the value to be cleared and force the
user to make a chose, set:

combobox1.listindex = -1

Brz



On Jul 23, 11:21*pm, PW <P...@discussions.microsoft.com> wrote:
> I have a combo box on a user form. *The first time I run it, it works fine. *
> The second time I run it. *It has the previous selection in it. *How can I
> have it come up blank?
>
> Thank You,
>
> PW


 
Reply With Quote
 
pw
Guest
Posts: n/a
 
      24th Jul 2008
The first time I run the macro, it works fine. The second time I can't get
the combobox to be blank even with the code you used below. Any idea why?

"brzak" wrote:

> Make use of teh ListIndex property
>
> From VBA Help:
> "Values of ListIndex range from –1 to one less than the total number
> of rows in a list (that is, ListCount – 1). When no rows are selected,
> ListIndex returns –1"
>
> so at whicever event you want the value to be cleared and force the
> user to make a chose, set:
>
> combobox1.listindex = -1
>
> Brz
>
>
>
> On Jul 23, 11:21 pm, PW <P...@discussions.microsoft.com> wrote:
> > I have a combo box on a user form. The first time I run it, it works fine.
> > The second time I run it. It has the previous selection in it. How can I
> > have it come up blank?
> >
> > Thank You,
> >
> > PW

>
>

 
Reply With Quote
 
brzak
Guest
Posts: n/a
 
      25th Jul 2008
I can only guess tht you're not resetting on all the possible events
where the user form appears.

A sample of the code would make it easier to see where the problem is.

Brz

On Jul 24, 10:23*pm, pw <p...@discussions.microsoft.com> wrote:
> The first time I run the macro, it works fine. *The second time I can'tget
> the combobox to be blank even with the code you used below. *Any idea why?
>
> "brzak" wrote:
> > Make use of teh ListIndex property

>
> > From VBA Help:
> > "Values of ListIndex range from –1 to one less than the total number
> > of rows in a list (that is, ListCount – 1). When no rows are selected,
> > ListIndex returns –1"

>
> > so at whicever event you want the value to be cleared and force the
> > user to make a chose, set:

>
> > combobox1.listindex = -1

>
> > Brz

>
> > On Jul 23, 11:21 pm, PW <P...@discussions.microsoft.com> wrote:
> > > I have a combo box on a user form. *The first time I run it, it works fine. *
> > > The second time I run it. *It has the previous selection in it. *How can I
> > > have it come up blank?

>
> > > Thank You,

>
> > > PW


 
Reply With Quote
 
pw
Guest
Posts: n/a
 
      25th Jul 2008
Yes, i agree. If I stop the macro, it resets and works OK. Here's one of
the form code.
No. 1:

Private Sub CommandButton2_Click()
EnterMenu.Hide
Sheets("Estimate").Select
ProjectNoMenu.Show

End Sub

Private Sub CommandButtonSaveRecordstoDatabase_Click()
PutData
End Sub

Private Sub UserForm_Initialize()
EnterMenu.StartUpPosition = CenterOwner
End Sub

No. 2 (for the combobox):

Private Sub ProjectNumberComboBox_Change()
'Brings up combo box with project numbers from column on "Dropdown Values"
worksheet
'
Dim PrNo As String
PrNo = ProjectNumberComboBox.Text
Sheets("Sample").Select
Range("a2") = PrNo
ProjectNoMenu.Hide
ContinueSearchData1

End Sub

Private Sub UserForm_Initialize()
Dim rowx As String
Dim PNRng As Range
Dim z As Variant

'ProjectNoMenu.StartUpPosition = CenterOwner

For Each C In ProjectNoMenu.Controls
If TypeOf C Is MSForms.ComboBox Then
C.Value = ""
End If
Next
Sheets("Dropdown Values").Select

rowx = Range("A2").End(xlDown).row
'Set the range to loop through
Set PNRng = Sheets("Dropdown Values").Range("A2:A" & rowx)

'Loops through the ranges
For Each z In PNRng

'Adds an item to the list
ProjectNumberComboBox.AddItem z.Value

Next z

ProjectNumberComboBox.ListIndex = -1
Sheets("Estimate").Select
End Sub



"brzak" wrote:

> I can only guess tht you're not resetting on all the possible events
> where the user form appears.
>
> A sample of the code would make it easier to see where the problem is.
>
> Brz
>
> On Jul 24, 10:23 pm, pw <p...@discussions.microsoft.com> wrote:
> > The first time I run the macro, it works fine. The second time I can't get
> > the combobox to be blank even with the code you used below. Any idea why?
> >
> > "brzak" wrote:
> > > Make use of teh ListIndex property

> >
> > > From VBA Help:
> > > "Values of ListIndex range from –1 to one less than the total number
> > > of rows in a list (that is, ListCount – 1). When no rows are selected,
> > > ListIndex returns –1"

> >
> > > so at whicever event you want the value to be cleared and force the
> > > user to make a chose, set:

> >
> > > combobox1.listindex = -1

> >
> > > Brz

> >
> > > On Jul 23, 11:21 pm, PW <P...@discussions.microsoft.com> wrote:
> > > > I have a combo box on a user form. The first time I run it, it works fine.
> > > > The second time I run it. It has the previous selection in it. How can I
> > > > have it come up blank?

> >
> > > > Thank You,

> >
> > > > PW

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fill combobox depending on selection from another combobox Adam Francis Microsoft Excel Misc 2 24th Jul 2008 07:39 PM
Filter one combobox based on another combobox selection =?Utf-8?B?Y29uZnUtc2Vk?= Microsoft Access Forms 5 11th Jul 2007 12:39 PM
ComboBox.Items.Clear() causes the selection of Text inside the edit of the ComboBox Nomasnd Microsoft Dot NET Framework Forms 1 27th Sep 2006 06:32 PM
Combobox items determined by the selection in another combobox =?Utf-8?B?QWxlcmlvbg==?= Microsoft Excel Programming 2 13th Sep 2006 01:07 PM
ComboBox Lookup Displays Value Before a Selection Is Made =?Utf-8?B?ZGFycmVw?= Microsoft Access Form Coding 1 5th Feb 2005 02:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:43 AM.