Connecting Tech Pros Worldwide Forums | Help | Site Map

Data type problems when concatenating fields.

Member
 
Join Date: Feb 2009
Posts: 43
#1: Apr 6 '09
Hi all;

I'm using this great bit of code to concatenate a fields from multiple rows into a single one.

Expand|Select|Wrap|Line Numbers
  1. 'Concat Returns lists of items which are within a grouped field
  2. Public Function Concat(strGroup As String, _
  3.                        strItem As String) As String
  4.     Static strLastGroup As String
  5.     Static strItems As String
  6.  
  7.     If strGroup = strLastGroup Then
  8.         strItems = strItems & ", " & strItem
  9.         Else
  10.         strLastGroup = strGroup
  11.         strItems = strItem
  12.     End If
  13.     Concat = strItems
  14. End Function
I tent to call the code using:

Expand|Select|Wrap|Line Numbers
  1. max(concat([tbl1]![field1],[tbl2]![field2]))
The problem I'm having is that I'm getting a Data Type Mismatch whenever I'm using a Number field as strGroup and a text field as strItem. Unfortunately I can't change the design of the underlying tables, the number fields have to remain as number fields.

Is there any way of tweaking the code to make it work with mixed data types? I've tried to look up info for CStr() but there's not much useful stuff out there!

Thanks!

Member
 
Join Date: Feb 2009
Posts: 43
#2: Apr 6 '09

re: Data type problems when concatenating fields.


Got it:

Expand|Select|Wrap|Line Numbers
  1. Last(concat([tblCustomers]![CustID],CStr(nz([policynumber]))))
Seems to be working...
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#3: Apr 6 '09

re: Data type problems when concatenating fields.


Nicely done Whizzo.

For the interest of anyone viewing this, not familiar with the Concat() function, see Combining Rows-Opposite of Union.
Reply