Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default combobox update

I have 2 comboboxes on a userform. If the one is chosen with data the second
one should be empty and vice versa.

I'm trying to do the following code but to chose the data I need to click
twice on a combobox if another one is with some data. The after-update gives
the same result.

Private Sub cboBox1_Change()
If Not IsNull(cboBox1.Value) Then
If Not IsNull(cboBox2) Then
cboBox2= Null
End If
cboBox1.SetFocus
End If
End Sub
Private Sub cboBox2_Change()
.....

How could I make it to get data right after the clicking.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default combobox update

How about something like:

Option Explicit
Dim BlkProc As Boolean
Private Sub ComboBox1_Change()
If BlkProc = True Then Exit Sub
Call CheckComboBoxes(1)
End Sub
Private Sub ComboBox2_Change()
If BlkProc = True Then Exit Sub
Call CheckComboBoxes(2)
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
'some test data
Dim iCtr As Long
For iCtr = 1 To 10
Me.ComboBox1.AddItem "A" & iCtr
Next iCtr
For iCtr = 11 To 20
Me.ComboBox2.AddItem "B" & iCtr
Next iCtr
End Sub
Sub CheckComboBoxes(WhichOne As Long)

Dim OtherOne As Long

If WhichOne = 1 Then
OtherOne = 2
Else
OtherOne = 1
End If

If Me.Controls("combobox" & WhichOne).Value = "" Then
'do nothing, it's empty
Else
BlkProc = True
Me.Controls("combobox" & OtherOne).Value = ""
BlkProc = False
End If

End Sub

The BlkProc almost works like .enableevents on a worksheet. But the code just
checks that variable and gets the heck out if the program is changing the
combobox.

(I did rely on the comboboxes having nice names--but you could pass it the name
of the current combobox and use that in the checkcomboboxes procedure.)

Alex wrote:

I have 2 comboboxes on a userform. If the one is chosen with data the second
one should be empty and vice versa.

I'm trying to do the following code but to chose the data I need to click
twice on a combobox if another one is with some data. The after-update gives
the same result.

Private Sub cboBox1_Change()
If Not IsNull(cboBox1.Value) Then
If Not IsNull(cboBox2) Then
cboBox2= Null
End If
cboBox1.SetFocus
End If
End Sub
Private Sub cboBox2_Change()
....

How could I make it to get data right after the clicking.

Thanks


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default combobox update

Thank you, Dave. It's working great.

"Dave Peterson" wrote:

How about something like:

Option Explicit
Dim BlkProc As Boolean
Private Sub ComboBox1_Change()
If BlkProc = True Then Exit Sub
Call CheckComboBoxes(1)
End Sub
Private Sub ComboBox2_Change()
If BlkProc = True Then Exit Sub
Call CheckComboBoxes(2)
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
'some test data
Dim iCtr As Long
For iCtr = 1 To 10
Me.ComboBox1.AddItem "A" & iCtr
Next iCtr
For iCtr = 11 To 20
Me.ComboBox2.AddItem "B" & iCtr
Next iCtr
End Sub
Sub CheckComboBoxes(WhichOne As Long)

Dim OtherOne As Long

If WhichOne = 1 Then
OtherOne = 2
Else
OtherOne = 1
End If

If Me.Controls("combobox" & WhichOne).Value = "" Then
'do nothing, it's empty
Else
BlkProc = True
Me.Controls("combobox" & OtherOne).Value = ""
BlkProc = False
End If

End Sub

The BlkProc almost works like .enableevents on a worksheet. But the code just
checks that variable and gets the heck out if the program is changing the
combobox.

(I did rely on the comboboxes having nice names--but you could pass it the name
of the current combobox and use that in the checkcomboboxes procedure.)

Alex wrote:

I have 2 comboboxes on a userform. If the one is chosen with data the second
one should be empty and vice versa.

I'm trying to do the following code but to chose the data I need to click
twice on a combobox if another one is with some data. The after-update gives
the same result.

Private Sub cboBox1_Change()
If Not IsNull(cboBox1.Value) Then
If Not IsNull(cboBox2) Then
cboBox2= Null
End If
cboBox1.SetFocus
End If
End Sub
Private Sub cboBox2_Change()
....

How could I make it to get data right after the clicking.

Thanks


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cut/Copy Combobox - I can't update MBais Excel Programming 2 July 22nd 05 02:26 PM
Update Combobox with New Data keepitcool Excel Programming 0 June 3rd 04 08:15 AM
combobox update Josh[_9_] Excel Programming 2 February 24th 04 05:22 PM
Combobox update Robert Couchman[_4_] Excel Programming 0 February 20th 04 09:13 AM
Dynamic update on ComboBox Kevin Excel Programming 4 October 14th 03 12:45 PM


All times are GMT +1. The time now is 01:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"