Kim:
It gets to be even more fun now!
Keep the three columns; its always easier to combine values form more than
one column than to parse a single column into two or more values.
In the Areas table you'll store the CustomerID of course, regardless of
what's in the other columns, so you can control what you see in the combo box
to handle the possible scenarios you describe. Set up the combo box like
this:
RowSource: SELECT CustomerID, (FirstName+" ") & (LastName) & IIf(
IsNull(LastName),CompanyName,(", " + CompanyName)) AS FullName FROM Customers
ORDER BY CompanyName & LastName & FirstName;
BoundColum: 1
ColumnCount: 2
ColumnWidths 0cm;8cm
If your units of measurement are imperial rather than metric Access will
automatically convert the last one (that's for the benefit of Americans, who
still use inches, but probably not relevant in your case, I'd guess). The
important thing is that the first dimension is zero to hide the first column
and that the second is at least as wide as the combo box.
This works because Nulls 'propagate', i.e. Null + anything = Null. So
(FirstName+" ") will only add a space after the first name if a first name is
entered in the field. Similarly IIf( IsNull(LastName),CompanyName,(", " +
CompanyName)) inserts the company name on its own if no last name is in the
field, or, if a last name has been entered, a comma and a space followed by
the company name if a company name has entered. So the value in the
computed FullName column if only personal names are entered might be 'Ken
Sheridan', if both personal and company names are entered ''Ken Sheridan,
Sheridan Widgets', or if only a company name is entered 'Sheridan Widgets'.
This is what you'd see in the combo box, but its value would be the
CustomerID value in each case. The list would be ordered alphabetically by
company name if a company has been entered, otherwise by last name.
When compiling mailing lists from the database you can use a query similar
to that used as the RowSource above for the RecordSource of a report; you'd
just need to add in the address columns, though you'd probably want to insert
carriage returns/line breaks (Chr(13) & Chr(10)) between the columns so each
appears on a separate line. The query would go something like this:
SELECT Customers.CustomerID, (FirstName+" ") & (LastName) &
IIf(IsNull(LastName),CompanyName,(Chr(13) & Chr(10) + CompanyName)) &
(Chr(13) & Chr(10) + Address1) & (Chr(13) & Chr(10) + Address2) & (Chr(13) &
Chr(10) + City) & (Chr(13) & Chr(10) + PostCode) AS FullAddress FROM
Customers ORDER BY CompanyName & LastName & FirstName;
which would give results such as:
Ken Sheridan
Sheridan Widgets
42 Nameless Street
Stafford
ST66 9LG
or:
Sheridan Widgets
42 Nameless Street
Stafford
ST66 9LG
or:
Ken Sheridan
42 Nameless Street
Stafford
ST66 9LG
depending on what data had been entered.
BTW there was once a company called 'Sheridan Widgets' which produced Visual
Basic add-ins, but it had no connection with me.
If you have any problems implementing the above mail me at:
kenwsheridan<at>yahoo<dot>co<dot>uk
and I can send you a file with the queries etc.
Ken Sheridan
Stafford, England