Solved

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

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

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 …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

910 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

21 Experts available now in Live!

Get 1:1 Help Now