Update combobox value while dirty

lenni

New member
Local time
Today, 17:44
Joined
Nov 10, 2012
Messages
7
Hey there, I'm new to the forum.

I've got a form with textboxes and comboboxes and I'm trying to set up some "hotkeys" so that if the user presses an F-key while still writing on the controls, a certain function will be run.

So for each of the controls I'm writing an OnKeyDown event. The problem is that, as the active control is still "dirty", MyControl.value is generally null, and I need to update the value to work with it later. Am I being clear?

I've solved it for textboxes with
Me.ActiveControl.Value = Me.ActiveControl.Text
and it works like a charm. But I'm stuck with the comboboxes.

How can I make the combobox.value update as if the user had hit the enter key? They are typical two-column comboboxes with a hidden bound first column which stores an id and a second column with text that might be partly written by the user.

Thanks a lot for your help,
Lenni.
 
Welcome to the forum.

Me.YourComboName.Text should return the text in the combo box.
 
Thanks for your reply.

Yes, I know, but the problem is that it's not easy to update Me.MyComboName.Value from Me.MyComboName.Text because it's a two-column combobox, as I explained above. So while "value" refers to the first column, "text" matches (at least in part) the second column. And I forgot to say that I'm working in an unbound form, so Me.dirty is useless.

I found a solution, though. Here I share it:
Code:
Private Sub chequearTeclas(teclita As Integer)
    Select Case teclita
        Case vbKeyF3:
            Select Case Me.ActiveControl.ControlType
                Case acTextBox:
                    If Me.ActiveControl.Text = "" Then
                        Me.ActiveControl.Value = Null
                        Else: Me.ActiveControl.Value = Me.ActiveControl.Text
                    End If
                Case acComboBox:
                    If Me.ActiveControl.Text = "" Then
                        Me.ActiveControl.Value = Null
                    Else:
                        Dim i As Long, flag As Boolean
                        flag = False
                        i = 0
                        Do
                            If (Me.ActiveControl.Column(1, i) = UCase(Me.ActiveControl.Text)) Then
                                Me.ActiveControl.Value = Me.ActiveControl.ItemData(i)
                                flag = True
                            End If
                            i = i + 1
                        Loop Until flag Or (i = Me.ActiveControl.ListCount)
                    End If
            End Select
            Me.SUBFORM_BUSQUEDA.Form.Origen
            Me.SUBFORM_BUSQUEDA.Form.Requery
        Case vbKeyF9:
            openReservation
        Case vbKeyF7:
            clearForm
    End Select
End Sub

I had to explore most of the properties available for comboboxes, and it's a bit complicated, but it works just as I wanted. Thanks for your time.
 

Users who are viewing this thread

Back
Top Bottom