Link to home
Start Free TrialLog in
Avatar of russell12
russell12Flag for United States of America

asked on

put first letter of combobox in a text box

Ok this is going to be hard to explain, but what I am trying to accomplish is putting only the first letter of a combo box into a text box.  For example, if I put Security Cameras in cmbcategory, txtinventory number should start with a "S".  I dont know if this is possible, so if anyone could give me suggestions/solution I would be greatly appreciated.  Thanks in advance!!!
Avatar of PeteEngineer
PeteEngineer
Flag of India image

Let me make sure I understand what you're asking. You have a dropdown based on a query with several fields. When you select an item from the dropdown, you'd like to populate other text boxes on the form with additional information from the dropdown.

Here is how I've accomplished this. Rather than refering to the query behind the dropdown, I simply do a one-time query on the original table. I'm somewhat new at Access, too. (Forced to convert from Visual FoxPro.) There may be a way to do the same thing with the dropdown's query.

This is an Access 2003 example. I don't know if the DAO.recordset type translates to newer or older versions.

For the After Update event on the dropdown add the following code:

Private Sub Dropdown1_AfterUpdate()
    Dim dbTemp As Database
    Dim rsTemp As DAO.Recordset

    'Open connection to current Access database and perform the search
    Set dbTemp = CurrentDb()
    Set rsTemp = dbTemp.OpenRecordset( _
       "SELECT LastName,FirstName FROM Employee_List where " _
       & "EmployeeCode = " & Str(me.Dropdown1.value))

    'Update other fields if data is found
    If rsTemp.EOF = False Then
       me.LastName.value = rsTemp("LastName")
       me.FirstName.value = rsTemp("FirstName")
    Else
       me.LastName.value = ""
       me.FirstName.value = ""
    End If

    rsTemp.Close
    Set rsTemp = Nothing

End Sub

Open in new window

Or



Private Sub ComboBox1_Change()

'note:  the default property is .Text

TextBox1 = ComboBox1

End Sub

Open in new window

Avatar of russell12

ASKER

No not actually, What I am looking for is if I select Security Cameras, my text box will display S automatically.  I have a script, but it isnt working all that well right now.  This might help you understand what I want.  Thanks!!

txtInventory.Value = txtfirstdigitcategory.Value & "-" & Nz(DMax("[Inventory #]", "tblinventory") + 1)
ASKER CERTIFIED SOLUTION
Avatar of Flyster
Flyster
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial