Solved

put first letter of combobox in a text box

Posted on 2012-04-12
4
295 Views
Last Modified: 2012-04-12
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
Comment
Question by:russell12
  • 2
4 Comments
 
LVL 8

Expert Comment

by:PeteEngineer
ID: 37841106
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
 
LVL 8

Expert Comment

by:PeteEngineer
ID: 37841110
Or



Private Sub ComboBox1_Change()

'note:  the default property is .Text

TextBox1 = ComboBox1

End Sub

Open in new window

0
 
LVL 2

Author Comment

by:russell12
ID: 37841115
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
 
LVL 22

Accepted Solution

by:
Flyster earned 500 total points
ID: 37841119
In the Control Source of your textbox put:

=Left(cmbcategory.value,1)

Flyster
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

744 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

13 Experts available now in Live!

Get 1:1 Help Now