I am using a Concatenation Function I have used for years and now suddenly it does not work.
I need to get all multiple records for an Admin into one single field.
I have a query I am using to stack records prior to concatenation
SQL -
SELECT qry_30DaysExp.Functional_Admin AS Admin, "Manager - " & [Department_Manager] & Chr(13) & Chr(10) & "Contractor Name - " & [Contractor_LastName] & ", " & [Contractor_FirstName] & Chr(13) & Chr(10) & "Contractor ID - " & [Contractor_ID] & Chr(13) & Chr(10) & "Start Date - " & [Contractor_Orig_StDate] & Chr(13) & Chr(10) & "End Date - " & [Contractor_End_Date] & Chr(13) & Chr(10) & "Hourly Rate - " & Format([Onsite_Hrly_Rate],"Currency") & Chr(13) & Chr(10) & "Keyfob Provided - " & Format([Keyfob_Provided],"True/False") & Chr(13) & Chr(10) & "Keyfob Returned - " & Format([Keyfob_Returned],"True/False") & Chr(13) & Chr(10) & "Badge Provided - " & Format([Badge_Provided],"True/False") & Chr(13) & Chr(10) & "Badge Returned - " & Format([Badge_Returned],"True/False") & Chr(13) & Chr(10) & "Laptop Provided - " & Format([Laptop_Provided],"True/False") & Chr(13) & Chr(10) & "Laptop Returned - " & Format([Laptop_Returned],"True/False") AS Contractor_Exp_String
FROM qry_30DaysExp
ORDER BY qry_30DaysExp.Functional_Admin;
Results are Perfect
Manager - Doe, John
Contractor Name - Doe, Ann
Contractor ID - 370
Start Date - 8/18/2008
End Date - 2/27/2009
Hourly Rate - $85.00
Keyfob Provided - False
Keyfob Returned - False
Badge Provided - False
Badge Returned - False
Laptop Provided - False
Laptop Returned - False
However when I use the function in a query this way ContExpList_CompleteOrig: IIf([Admin] Is Not Null,GetFieldFromMultiRecords(2,[Admin],"Qry_Concatenated_Exp_Contractors_Base","Admin","Contractor_Exp_String"),"")
(code for function in code section) it returns the following
Manager - Doe, John
Contractor Name - Doe, Ann
Contractor ID - 370
Start Date - 8/18/2008
End Date - 2/27/2009
Hourly Rate - $85.00
Keyfob Provided - False
Keyfob Returned - False
Badge Provided - False
Badge Returned - False
Laptop Provisì@üsì@L#$vL#@L#@
If I shorten the number of fields I am using to just through Badge Provided everything works fine.
I need this concatenation to fully work. The results have to be placed on the body of an e-mail.
What can I do to fix this? Thanks
Function GetFieldFromMultiRecords(pbytKeyType As Byte, pvarID As Variant, pstrTable As String, pstrIDField As String, pstrMergeField As String) As String
On Error GoTo ErrHandle_Err
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strReturnValue As String
Dim strWHERE As String
strWHERE = " WHERE [" & pstrIDField & "]="
Select Case pbytKeyType
Case 1: strWHERE = strWHERE & pvarID
Case 2: strWHERE = strWHERE & Chr(34) & pvarID & Chr(34)
Case 3: strWHERE = strWHERE & "#" & Format(CDate(pvarID), "MM/DD/YYYY HH:NN:SS") & "#"
End Select
Set db = CurrentDb()
Set rst = db.OpenRecordset("SELECT [" & pstrMergeField & "] FROM " & pstrTable & strWHERE)
Do While Not rst.EOF
strReturnValue = strReturnValue & vbCrLf & rst("[" & pstrMergeField & "]")
'strReturnValue = strReturnValue & ", " & Chr(13) & Chr(10) & rst("[" & pstrMergeField & "]")
rst.MoveNext
Loop
If Len(strReturnValue) > 0 Then strReturnValue = Mid(strReturnValue, 3)
GetFieldFromMultiRecords = strReturnValue
ErrHandle_Exit:
Exit Function
ErrHandle_Err:
MsgBox Error$
Resume ErrHandle_Exit
End Function
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
Select allOpen in new window
by: quizzerPosted on 2009-02-20 at 12:28:37ID: 23695835
Or is there a way to merge a multiple record query as text into the body of an e-mail.
Email Code Below
Select allOpen in new window