Solved

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

Posted on 2011-03-04
2
348 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

778 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