Results 1 to 6 of 6
  1. #1
    Renee R is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    11

    Text Box filling in after combo box selected, need to sort on split form

    This is a very simplified version of what I'm trying to do...

    I have a table [Employees] that has the field [FirstName] and [LastName]. On my form [Jobs], I have a combobox [ComboWho]. The combo box has all of the possible first names. When a first name is picked, it makes the last name fill in a textbox.

    In the real version, it is a [LastName] is a lot of information, so it is kept in a memo field. I tried to use cascading combo boxes, but it cuts off my text.



    I keep getting it to almost work... I've tried about 5 different methods... DLookUp, subform, etc.

    Right now, I'm using this code:

    Private Sub ComboWho_Change()
    Dim location As String
    Me.ComboWho.SetFocus
    location = DLookup("LastName", "Employee", "FirstName = '" & Me.ComboWho.SelText & "'")
    Me.MyTextBox.SetFocus
    Me.MyTextBox.Text = location
    End Sub

    It has properly filled in the textbox. I thought it was working perfectly, but ran into one snag... We have been using a split form... and it won't let me filter that column (Column ComboWho). I think because it is saving everything as numbers instead of text.

    ComboWhoDatabase.accdbI've attached a copy of the simplified database... any help would be appreciated.

    Thanks!
    Renee

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Don't understand what is meant by 'kept in a memo field' - why would LastName be a memo field? It is not in the posted database.

    Yes, the DLookup doesn't work because the actual value of combobox is the EmployeeID, not FirstName. Text is the wrong property anyway, should be Value. But since Value is the default property of data controls, can be omitted. Also, SelText does apply here, Value would but can be omitted.
    Me.MyTextBox = DLookup("LastName", "Employee", "EmployeeID = " & Me.ComboWho)

    Why is selection made by first name? What if you have several Robert or James? Consider this as combobox RowSource:

    SELECT [EmployeeID], [LastName & ", " & [FirstName] AS EmpName FROM Employee ORDER BY [LastName], [FirstName];

    If you must search by FirstName, then combobox RowSource:

    SELECT [EmployeeID], [FirstName] & " " & [LastName] FROM Employee ORDER BY [FirstName];

    No code and no textbox needed for either.

    However, if you want textbox:

    SELECT [EmployeeID], [FirstName], [LastName] FROM Employee ORDER BY [FirstName];

    Then expression in textbox:

    =[ComboWho].[Column](2)

    Column index begins with 0. LastName is column 3 so index 2.

    Again, no code.

    The Who field in Jobs table should be number type because the EmployeeID primary key is an autonumber. Related PK and FK fields must be same type - in this case, autonumber and number.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Renee R is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    11
    Quote Originally Posted by June7 View Post
    Don't understand what is meant by 'kept in a memo field' - why would LastName be a memo field? It is not in the posted database.
    Sorry... I tried to make a simplified version of what I'm trying to do, so that it would be easier to spot the mistakes. I've updated the posted database to reflect what I'm trying to do. In one of my text boxes, it will show LastName. This isn't the problem, I can do that. The problem is that in another text box, I want it to show the EmployeeInfo, which is a lot of information... so it has to be kept in a memo field. I've made these changes.


    Quote Originally Posted by June7 View Post
    Why is selection made by first name? What if you have several Robert or James?
    In the real database, each item has a unique name, so there is no worry about several Roberts or James.

    Quote Originally Posted by June7 View Post
    However, if you want textbox:

    SELECT [EmployeeID], [FirstName], [LastName] FROM Employee ORDER BY [FirstName];

    Then expression in textbox:

    =[ComboWho].[Column](2)

    Column index begins with 0. LastName is column 3 so index 2.

    Again, no code.
    I have tried this... however, because the data I want displayed is in a memo field, it truncates it. I need to find a method that will show more text.

    Quote Originally Posted by June7 View Post
    The Who field in Jobs table should be number type because the EmployeeID primary key is an autonumber. Related PK and FK fields must be same type - in this case, autonumber and number.
    Is there any way to get it to save from a combo box as the text that was selected, not the primary key? I don't want to have to loop up what each number means when I'm in datasheet view.

    Thanks!
    Renee
    Attached Files Attached Files

  4. #4
    Renee R is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    11
    I've tried again... no luck!

    I've erased and remade my comboboxes again. They now sort in the datasheet beautifully.

    I have my combobox [ComboWho] that selects who is doing the job. Then, in the text box [MyTextBox], I've put this as the Control Source =DLookUp("EmployeeInfo","Employee","EmployeeID = " & [Me].[ComboWho])

    All I get in the TextBox is #Name?

    Renee
    Attached Files Attached Files

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Remove Me. from the textbox expression. The Me qualifier is only valid in VBA.

    Domain aggregate expressions can be slow. Alternatively, try this as the form RecordSource:
    SELECT Jobs.*, Employee.EmployeeInfo FROM Employee RIGHT JOIN Jobs ON Employee.EmployeeID = Jobs.Who;

    Bind textbox to the EmployeeInfo field and set it as Locked Yes, TabStop No.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Renee R is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    11
    It worked! removing the [Me] made it work! Thank you so much.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Split form Datasheet Sort from A to Z
    By data808 in forum Forms
    Replies: 3
    Last Post: 03-30-2014, 12:43 AM
  2. Cascading combo box - sort text numerically
    By motormouth1991 in forum Access
    Replies: 4
    Last Post: 05-23-2013, 06:49 AM
  3. Replies: 3
    Last Post: 10-16-2012, 10:34 AM
  4. Code to sort data shown on a split form
    By meissnerb in forum Programming
    Replies: 1
    Last Post: 05-03-2012, 04:34 PM
  5. Get combo box selected text.
    By allstar45 in forum Programming
    Replies: 1
    Last Post: 02-16-2012, 10:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums