ComboBox Change Command

clebo99
01-06-2005, 12:01 PM
Hey,

I have a combobox in a form that has a list of say system names from a SQL DB, single table. On the form are other text boxes, labels etc that would contain inventory information.

What I want to do is when I select the system name in the combo box, the inventory information comes up. I know this is easily done if I add a command button named "Search" or something, but I want this to occur the second the selection has been made in the combo box.

I thought that the "Change" control on the combo box did this but it's not working. I even put in a test MSGBOX to pop up when this action occurs but that is not occurring.

Code:

Dim infolist As New ADODB.Recordset
.
.
.
.
.
Private Sub Serverlist_Change()
MainForm.Refresh

Dim str As String

MsgBox "Combo Box Info Changed"

'setting all labels and boxes to blank
IPLabel.Caption = ""
NetworkCardLabel.Caption = ""
StorageLabel.Caption = ""
FailoverLabel.Caption = ""
BackupStatus.Text = ""
DataDirectories.Text = ""
Failoversteps.Text = ""
Localadmins.Text = ""

opendatabase

With infolist
.ActiveConnection = cn
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Open "SELECT * FROM sysinfo WHERE Sysname='" & Serverlist.Text & "'"
' Put entries into data here....
IPLabel.Caption = !sysip
NetworkCardLabel.Caption = !sysnetcard
StorageLabel.Caption = !sysstorage
FailoverLabel.Caption = !sysfailstatus
BackupStatus.Text = !sysbackup
DataDirectories.Text = !sysdata
Failoversteps.Text = !sysfailover
Localadmins.Text = !sysadmins

Wend

.Close
MainForm.Refresh

Thoughts?

Chris, Baltimore

noi_max
01-06-2005, 01:49 PM
Have you tried the Combobox's Click event instead?
It might not fit your solution, but it was the first thing that came to mind.

Rockyh
01-06-2005, 02:43 PM
Once upon a time Microsoft posted a solution to this. However, it was not totally correct (at least for VB 6).

In order to do this, you need to make an API call to SendMessage to get the state of the combo box. VB does fire an event when the combo box is dropped down, so use that to start a timer that will continually check when the combo box is retracted (user has selected something).


Const CB_GETDROPPEDSTATE = &H157 'You can find doc on this in the SDK

Private Sub cboCombo_DropDown()

Timer1.Interval = 1 ' Start Timer to check for retraction
Timer1.Enabled = True

End Sub


Private Sub Timer1_Timer()
Dim lngMessage As Long

lngMessage = SendMessage(cboCompatibility.hWnd, _
CB_GETDROPPEDSTATE, 0&, 0&)
If lngMessage = 0 Then
' Retraction event, list is no longer displayed
' insert your code here
End If
End Sub

Rocky



Hey,

I have a combobox in a form that has a list of say system names from a SQL DB, single table. On the form are other text boxes, labels etc that would contain inventory information.

What I want to do is when I select the system name in the combo box, the inventory information comes up. I know this is easily done if I add a command button named "Search" or something, but I want this to occur the second the selection has been made in the combo box.

I thought that the "Change" control on the combo box did this but it's not working. I even put in a test MSGBOX to pop up when this action occurs but that is not occurring.

Code:

Dim infolist As New ADODB.Recordset
.
.
.
.
.
Private Sub Serverlist_Change()
MainForm.Refresh

Dim str As String

MsgBox "Combo Box Info Changed"

'setting all labels and boxes to blank
IPLabel.Caption = ""
NetworkCardLabel.Caption = ""
StorageLabel.Caption = ""
FailoverLabel.Caption = ""
BackupStatus.Text = ""
DataDirectories.Text = ""
Failoversteps.Text = ""
Localadmins.Text = ""

opendatabase

With infolist
.ActiveConnection = cn
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Open "SELECT * FROM sysinfo WHERE Sysname='" & Serverlist.Text & "'"
' Put entries into data here....
IPLabel.Caption = !sysip
NetworkCardLabel.Caption = !sysnetcard
StorageLabel.Caption = !sysstorage
FailoverLabel.Caption = !sysfailstatus
BackupStatus.Text = !sysbackup
DataDirectories.Text = !sysdata
Failoversteps.Text = !sysfailover
Localadmins.Text = !sysadmins

Wend

.Close
MainForm.Refresh

Thoughts?

Chris, Baltimore

Rockyh
01-06-2005, 02:47 PM
I forgot to show that you should disable the timer once the SendMessage call returns with a zero. Also, don't forget to prototype the SendMessage call:
Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, ByVal Msg As Long, _
wParam As Any, lParam As Any) As Long

clebo99
01-07-2005, 01:39 PM
The CLICK event worked like a charm!!!

Thanks guys!!

Chris

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum