Sola
Registered User.
- Local time
- Today, 00:36
- Joined
- Jun 1, 2007
- Messages
- 14
Hi, everyone. I have a database (example included) where I can't get a query to work like I want. I have looked online, but the examples don't seem to match my problem (or I am missing something). Here is the setup:
tblMain is set up with one record for each acct #.
tblClient contains the first and last names of each client. There can be up to 4 clients on each account, so the table is set up in a many-to-one relationship with tblMain. The # in the Position field indicates the order in which the clients are listed on the account.
I am trying to set up a query (for later use in a report) that displays like this:
Acct, Client1, Client2, Client3, Client4, OtherInfo.
I have used both Iif and Switch to get the first and last names to drop into the correct ClientX slot (based on position), but it isn't combining them into one row.
Qry:
Acct, Client1: Iif([Position]=1,[LastName] & ", " & [FirstName], Null), Client2: Iif([Position]=1,[LastName] & ", " & [FirstName], Null), etc.
Result:
Acct / Client1 / Client2 / Client3 / Client4 / OtherInfo
123 / Abigail / (null) / (null) / (null) / Zzz
123 / (null) / Adam / (null) / (null) / Zzz
123 / (null) / (null) / Alice / (null) / Zzz
123 / (null) / (null) / (null) / Ansel / Zzz
Qry:
Acct, Client1: Switch([Position]=1,[LastName] & ", " & [FirstName],[Position]=2,[LastName] & ", " & [FirstName],[Position]=3,[LastName] & ", " & [FirstName],[Position]=4,[LastName] & ", " & [FirstName]), Client2: Switch([Position]=2,[LastName] & ", " & [FirstName],[Position]=3,[LastName] & ", " & [FirstName],[Position]=4,[LastName] & ", " & [FirstName]), etc.
Result:
Acct / Client1 / Client2 / Client3 / Client4 / OtherInfo
123 / Abigail / (null) / (null) / (null) / Zzz
123 / Adam / Adam / (null) / (null) / Zzz
123 / Alice / Alice / Alice / (null) / Zzz
123 / Ansel / Ansel / Ansel / Ansel / Zzz
tblMain is set up with one record for each acct #.
tblClient contains the first and last names of each client. There can be up to 4 clients on each account, so the table is set up in a many-to-one relationship with tblMain. The # in the Position field indicates the order in which the clients are listed on the account.
I am trying to set up a query (for later use in a report) that displays like this:
Acct, Client1, Client2, Client3, Client4, OtherInfo.
I have used both Iif and Switch to get the first and last names to drop into the correct ClientX slot (based on position), but it isn't combining them into one row.
Qry:
Acct, Client1: Iif([Position]=1,[LastName] & ", " & [FirstName], Null), Client2: Iif([Position]=1,[LastName] & ", " & [FirstName], Null), etc.
Result:
Acct / Client1 / Client2 / Client3 / Client4 / OtherInfo
123 / Abigail / (null) / (null) / (null) / Zzz
123 / (null) / Adam / (null) / (null) / Zzz
123 / (null) / (null) / Alice / (null) / Zzz
123 / (null) / (null) / (null) / Ansel / Zzz
Qry:
Acct, Client1: Switch([Position]=1,[LastName] & ", " & [FirstName],[Position]=2,[LastName] & ", " & [FirstName],[Position]=3,[LastName] & ", " & [FirstName],[Position]=4,[LastName] & ", " & [FirstName]), Client2: Switch([Position]=2,[LastName] & ", " & [FirstName],[Position]=3,[LastName] & ", " & [FirstName],[Position]=4,[LastName] & ", " & [FirstName]), etc.
Result:
Acct / Client1 / Client2 / Client3 / Client4 / OtherInfo
123 / Abigail / (null) / (null) / (null) / Zzz
123 / Adam / Adam / (null) / (null) / Zzz
123 / Alice / Alice / Alice / (null) / Zzz
123 / Ansel / Ansel / Ansel / Ansel / Zzz