Let me back up for a minute.
First, make sure there is a key on your table. Usually it's called ID, and it's set up as Autokey, unique, indexed.
Second, when you load the list box, you include the key as one of the columns. It can be hidden, so the user doesn't see it, but the programmer needs to know it's there.
So, let's say the listbox [lstCity] is going to have cities in it, and the RowSource is
Code:
="SELECT cityID, cityName & "", "" & cityState FROM Cities;"
The Bound column is 1, and column width is 0",2" so that only the city name and state shows. LimitToList is set to yes.
Here's a reference that you can look at for list boxes -
http://office.microsoft.com/en-us/ac...005187786.aspx
Here's a random example of what those values loaded in the listbox might be. Only the second column would be displayed.
Code:
13 Cincinatti, OH
24 Frisco, TX
69 San Francisco, CA
92 Zumberg, LA
So, when someone picks Cincinatti, OH out of the City list, the control [lstCity] then has the value 13. If they pick San Francisco, CA, it gets the value 69.
Behind your button that says "Increment", there will be code that builds and runs the SQL. There's usually error trapping and so on, but it boils down to this:
Code:
Dim strSQL AS string
strSQL = "UPDATE [Cities] SET [visitors] = [visitors] + 1 WHERE [CityID] = " & [lstCity] &";"
DoCmd.RunSQL strSQL
So, if the user picked Cincinatti, the value of [lstCity] would become 13, and the strSQl would look like this:
Code:
UPDATE [Cities] SET [visitors] = [visitors] + 1 WHERE [CityID] = 13;
That SQL, when executed, will update one, and only one, record on the [Cities] table.