Ask Your Question
0

Base Form List Box for states [closed]

asked 2017-10-02 03:48:01 +0200

Joe Castor gravatar image

In a Base Form (NewMembers) I use a List Box to select a State or Province from a States table that contains SPid, SPName and Abv columns (in that order). A 2 character code (Abv) is then stored in the State/Providence of a new record. My issue is that I would like to "show" the spelled out state or province name (SPName) in the list box, but when selecting the state/province, I return the Abv field into the St/Prov form field. I can get one or the other, but not the combination. The Sql code is SELECT "Abv" FROM "States" ORDER BY "SPid" ASC I tried adding SPName,and concat (||) to no avail. I've spent considerable search time and thought I'd find a lot of examples, but nothing. Any help is appreciated. Joe C

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Joe Castor
close date 2017-10-02 06:32:06.030135

1 Answer

Sort by » oldest newest most voted
0

answered 2017-10-02 04:37:14 +0200

Ratslinger gravatar image

updated 2017-10-02 05:15:17 +0200

Sorry you spent considerable time searching for this. Have posted this a time or two.

In your list box, on the Properties Data tab, Type of list contents should be Sql, as I'm certain you have. Your SQL statement should be:

 SELECT "SPName", "Abv" FROM "States" ORDER BY "SPNAME" ASC

Then Bound field should be 1.

The first field in the Select statement is what is displayed in the list box (which is why the Order By change). The Bound Field is what is stored in the record with the first field selected being '0' and the second field is '1'. Thus you will display the full state name and save the abbreviated name.

An aside here, don't know why you have an ID field in this table as the State name or abbreviation is unique and can serve as the key here.

Edit:

Sample - ListBoxAltSave.odb

edit flag offensive delete link more

Comments

I copied the table from some web site and used it as copied, thus the SPid. Yes, sql is selected. I tried your suggestion but it didn't work. SPName was returned instead of Abv. I double checked your instructions (actually I copied and pasted them), and set bound field to 1. Did I miss something?

Joe Castor gravatar imageJoe Castor ( 2017-10-02 05:07:06 +0200 )edit

Should be OK. Not sure why it didn't work. See sample in edited answer. Doesn't use states but should give you same concept. Can provide state sample is really needed.

Ratslinger gravatar imageRatslinger ( 2017-10-02 05:16:26 +0200 )edit

I downloaded/looked at your sample and in both list boxes the choices are what is entered into the table fields, so it isn't a comparative to "pick A, use B. The examples are similar to what I have now.

Joe Castor gravatar imageJoe Castor ( 2017-10-02 05:27:01 +0200 )edit

Maybe I don't understand what you are looking for. As I understand, you have a new/existing member. For the state field in that record you want to use a list box. The list box should display the FULL name of the state but store the abbreviated name in the member record. Is that correct?

Ratslinger gravatar imageRatslinger ( 2017-10-02 05:46:11 +0200 )edit

Also, did you actually look at the table? Not via the form! The form translates it right back from abbreviated to full for display only. On the sample the table PRIMARY, if displayed, will show that the ID field is stored.

Ratslinger gravatar imageRatslinger ( 2017-10-02 05:48:35 +0200 )edit

I looked at the table after an update and it makes the entry/change correctly ( two digit code), but the form shows the full state/province name. Hmmm. A delima. do I change the form to reflect the long name to accommodate this change? When I select a different member, the two digit state now lists as the long name (or as much as can fit into the short box)..

Joe Castor gravatar imageJoe Castor ( 2017-10-02 06:18:40 +0200 )edit

As stated the list box is two way. Select a long name it saves the short. If the displayed record contains an abbreviated name matching one in the list box it will display the long name (or maybe even the one closest to it - never tried that).

If, however, you display this member field in say a text box, the abbreviated name will display because that is all it knows. Nothing to translate it.

Your decisions on what to display, store, translate.

Ratslinger gravatar imageRatslinger ( 2017-10-02 06:26:10 +0200 )edit

Okay, thanks. It's never easy, is it. I apppreciate your insight and wisdom.

Joe Castor gravatar imageJoe Castor ( 2017-10-02 06:31:41 +0200 )edit

Informational only - The reason to all this is saving storage within the database. You want to have meaningful names displayed but the amount of space consumed can greatly increase with the number of records. In the sample provided, only the key is stored. This is a great space saver over what may be a very long name - i.e. stock number vs item name in auto parts.

Ratslinger gravatar imageRatslinger ( 2017-10-02 06:38:43 +0200 )edit

Question Tools

1 follower

Stats

Asked: 2017-10-02 03:48:01 +0200

Seen: 278 times

Last updated: Oct 02 '17