Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

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!!!
0
russell12
Asked:
russell12
  • 2
1 Solution
 
PeteEngineerCommented:
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

0
 
PeteEngineerCommented:
Or



Private Sub ComboBox1_Change()

'note:  the default property is .Text

TextBox1 = ComboBox1

End Sub

Open in new window

0
 
russell12Author Commented:
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)
0
 
FlysterCommented:
In the Control Source of your textbox put:

=Left(cmbcategory.value,1)

Flyster
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now