Solved

put first letter of combobox in a text box

Posted on 2012-04-12
4
297 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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