5

I have a combo box in my form with Member IDs, when I select a member ID, I want my txtLastName text box to be set to the member's name. I know what to write for the SQL query, but I don't know how to run that query and obtain the resulting name and put it into a String.

How could this be done?

Thanks

jmasterx
  • 52,639
  • 96
  • 311
  • 557

1 Answers1

4

Access provides "out-of-the-box" solution for this without need for additional query. The idea is to use multiple columns from the combobox like this (in code):

Me.ComboBox.Column(N)

Check this out:

http://www.techrepublic.com/blog/msoffice/automatically-fill-in-access-text-boxes-based-on-a-combo-box-selection/1330

Igor Turman
  • 2,165
  • 1
  • 22
  • 25
  • Not quite. For a textbox you would say `=TheComboBox.Column(n)`, where n starts from zero. Note, no Me. – Fionnuala Apr 09 '12 at 15:17
  • Why does (1) work but (2) returns NULL yet there are 8 columns per row. – jmasterx Apr 09 '12 at 16:24
  • make sure your query returns data for that column. (1) and (2) there is no difference as long as you have so many columns in the query. Try giving all of the columns in the drop-down (combobox) fixed width and check it right from the form. Do you see the values for column 2 from the drop-down? – Igor Turman Apr 09 '12 at 16:40
  • If I set column count to 3 it works but then I see the last and first name in the combobox which I do not want to see. – jmasterx Apr 09 '12 at 16:49
  • you can hide all but display column(s) by setting width to 0. like this 0;1";0;0;0;0... Count should be set to the number of columns you need data from. – Igor Turman Apr 09 '12 at 16:50
  • this link might be helpful as well (ColumnWidths property): http://msdn.microsoft.com/en-us/library/aa224077(v=office.11).aspx – Igor Turman Apr 09 '12 at 16:54