Results 1 to 9 of 9
  1. #1
    Phil H is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2019
    Location
    Phoenix, AZ
    Posts
    19

    VBA behind a Combo Box


    This question involves using VBA behind a Combo Box. The Combo Box is bound to table CI and a field called APlayer. The search is on a field called LastName in another table PL. The objective is to get a second field, PlayerName from PL, stored in APlayer in the table CI. That seems to work OK, but the Combo Box on the form continues to display LastName, not the value in the bound field, PlayerName. I’ve even used code in an AfterUpdate event to search PL and place PlayerName in the form field with the command Me!APlayer = PL(“PlayerName”). That doesn’t work either and there are no error messages. I must be violating some basic rule about Combo boxes. Anyway, any help would be appreciated.
    Phil H

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Hi Phil,

    If I understand correctly what you want to achieve I don't think you need any VBA. For your bound combo box (to APlayer) set the Row Source property to "Select [Last Name],[PlayerName] FROM PL Order By [Last Name];", RowSourceType to Table/Query, Column Count to 2 and Column Widths to 0;3" and finally List Width to 3".

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Phil H is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2019
    Location
    Phoenix, AZ
    Posts
    19
    Thanks Vlad, but it still didn't quite work. I set up the combo box exactly as you suggested, but when I open the form with focus on the combo box and start typing a name (expecting last name) it starts displaying the full name (playername). i.e. I start typing "b r o" for Brown, but it comes up with Bill.... It looks like that is because of the column counts of 0",1"...I guess? When I changed it back to 1",1" it works the way it did before, stores player name in the table, but leaves lastname in the combo box. When I click on the down arrow in the combo box (with a width of 3") it displays both the lastname and the playername, but I don't really want the user to have to do that. Anyway, I'm using a workaround for the time being so it's not crucial to my work. Again, thanks for your help.
    Phil H

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,406
    This question involves using VBA behind a Combo Box. The Combo Box is bound to table CI and a field called APlayer. The search is on a field called LastName in another table PL. The objective is to get a second field, PlayerName from PL, stored in APlayer in the table CI. That seems to work OK, but the Combo Box on the form continues to display LastName, not the value in the bound field, PlayerName.
    See the red. That's the confusing point to me.
    Combobox can't work two ways like that. I suggest putting a bound textbox on the form to display the PlayerName after the unbound combobox lookup, like below attachment.

    PhilH-Players-davegri-v01.zip

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Can you try to change the bound column from 1 to 2?

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Hi Phil, I think I get what you want to achieve. If Dave's solution doesn't work you can try this approach.: set the combo to store and display player name when you are just looking at the form (save that SQL as the default rowsource). Then in the OnEnter event change the resource to another SQL statement that has Last Name as its first visible row (something like Select PlayerName,[Last Name],playerName from PL; with column widths 0;1;2); that will allow you to search by last name,view the full player name and store it. Finally in the OnExit event of the combo reset its rowsource to the original set to display the bound field.
    Cheers.

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Hi Phil and Dave,
    Here is what I had in mind, it seems to work for most parts but autoexpand doesn't....
    Sorry Dave for using your db!
    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,406
    PhilH-Players-davegri-v02.zip
    Autoexpand didn't work in my original V1. Autoexpand should be automatic. When it doesn't work, I recreate the combobox from scratch and then it does. Here's V2.

    Vlad- no problem! That's what it's for. Getting doggy around here, huh....

  9. #9
    Phil H is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2019
    Location
    Phoenix, AZ
    Posts
    19
    Quote Originally Posted by davegri View Post
    See the red. That's the confusing point to me.
    Combobox can't work two ways like that. I suggest putting a bound textbox on the form to display the PlayerName after the unbound combobox lookup, like below attachment.

    PhilH-Players-davegri-v01.zip

    I think I'll just go with the bound textbox approach to display PlayerName. Thanks to all who responded.
    Phil H

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

Similar Threads

  1. Replies: 5
    Last Post: 05-31-2017, 08:58 AM
  2. Replies: 3
    Last Post: 01-29-2016, 08:52 PM
  3. Replies: 7
    Last Post: 03-30-2015, 10:04 AM
  4. Replies: 2
    Last Post: 10-21-2014, 07:57 AM
  5. Replies: 1
    Last Post: 10-30-2012, 10:29 AM

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