Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-04
2
Medium Priority
?
363 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 600 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 1400 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

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.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

719 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