Solved

How to keep the value  of the text box in the combo box

Posted on 2011-03-04
2
344 Views
Last Modified: 2012-08-14
Let say i have a field called Status
when you create a  record, the status is "Intern"
so txtStatus.text="Intern"
I have Update button, it will open combo box Status with prefileed statutes :
Intern
Part Time
Full Time

so you have the ability to select something from the combo box and update the status, from Intern to Part Time or what ever...
But the original status should be preselected in combobox
0
Comment
Question by:rfedorov
2 Comments
 
LVL 26

Assisted Solution

by:Nick67
Nick67 earned 150 total points
ID: 35041111
OK.
In your cmdUpdateButton_Click() event you probably already have something like

me.cboStatus.visible = true

to make your combobox visible.  Now you just need

me.cboStatus.value = me.txtStatus.value

That will set the combobox value to that of the textbox, providing that all the data is set up as expected
(i.e. that txtStatus is bound to sometable!Status and the bound column of the combobox is bound to sometable!status

You've quoted       txtStatus.text="Intern"    in your post

Be aware that the .text and .value properties are NOT the same thing.  The .text is what you presently see -- even changes that haven't been committed to the table yet and can be reversed by a Cancel event or pressing the ESC key.  The .value is what is in the underlying table of a bound control.

.text can also only be accessed when the control has the focus.  .value can be accessed at any time in code.


0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 350 total points
ID: 35041159
as a test , does this code do what you are looking for ?


when you click the button1, the value of the text box (ie your field Status) is compared to the allowable values of the combo box.

If a match is found, the combo box is set to match. If no match, an alert is raised to note an invalid data. (ie color red)

when processing the update, you access the current indexed item of the combobox.
Private Sub Command1_Click()
       'check to validity
    Dim i As Integer: Dim ok As Boolean
    ok = False
    For i = 0 To Combo1.ListCount - 1
        If Text1.Text = Combo1.List(i) Then
            Combo1.ListIndex = i
            ok = True: Exit For
        End If
    Next i
    If ok Then
        Text1.BackColor = vbGreen
     Else
        Text1.BackColor = vbRed
    End If

End Sub

Private Sub Form_Load()
    Combo1.AddItem "Intern"
    Combo1.AddItem "Part Time"
    Combo1.AddItem "Full time"
    
    Text1.Text = "Intern"

End Sub

Private Sub cmdUpdate()
    Label1.Caption = Combo1.List(Combo1.ListIndex)
End Sub

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

This collection of functions covers all the normal rounding methods of just about any numeric value.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now