Solved

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

Posted on 2011-03-04
2
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This collection of functions covers all the normal rounding methods of just about any numeric value.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

728 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