Kryst51
Singin' in the Hou. Rain
- Local time
- Today, 01:55
- Joined
- Jun 29, 2009
- Messages
- 1,898
I have a dilemma. I am trying to concatenate records in a table to display on a form or a report. I have figured out (using a function I found on the internet) how to concatenate the records for display. However, I need to attach the date to it. For instance:
I would like it to display Like this in a text box if I was querying the fk number 5:
I have the following to put into a query. It works if I put it into the control source of a text box, but if I put it into a query it doesn't work I get an error.
This goes into my query:
Here is the Concatenate function (I put a break at the beginning of the function:
cn is another function which creates the connection.... I don't get the error on the cn module, but when it goes back to the concatenate function after running the cn function I get an error on line 20 which says "No value given for one or more required parameters." Error Number "-2147217904"
Here is the sql (That I have so far) for the query I am trying to create:
I intend to the concatenate the date with the concatenated error notes in the query. But I can't even get the concatenation of the error notes to work.
Any ideas or suggestions would be helpful (especially if there is an easier way to achieve my goal. As well as anything as to where I am going wrong. I hope I have given enough info (as well as not too much. )
Code:
AN Date Note fkIDforanothertable
1 01/01/11 This is the first Note. 5
2 01/01/11 This is the second Note 1
3 01/01/11 This is the third Note 5
4 01/02/11 This is the fourth Note 1
5 01/02/11 This is the fifth Note 5
I would like it to display Like this in a text box if I was querying the fk number 5:
01/01/11 - This is the first Note. This is the third Note
01/02/11 - This is the fifth Note.
I have the following to put into a query. It works if I put it into the control source of a text box, but if I put it into a query it doesn't work I get an error.
This goes into my query:
ErrorDescription: Concatenate("SELECT ErrorNote FROM tblErrorNotes WHERE pkNCRIssueID =" & [fkNCRIssueID])
Here is the Concatenate function (I put a break at the beginning of the function:
Code:
Function Concatenate(pstrSQL As String, Optional pstrDelim As String = ". ", _
Optional pstrLastDelim As String = ".") _
As Variant
10 On Error GoTo Concatenate_Error
Dim rs As New ADODB.Recordset
20 rs.Open pstrSQL, cn
Dim strConcat As String 'build return string
30 With rs
40 If Not .EOF Then
50 .MoveFirst
60 Do While Not .EOF
70 strConcat = strConcat & _
.Fields(0) & pstrDelim
80 .MoveNext
90 Loop
100 End If
110 .Close
120 End With
130 Set rs = Nothing
140 If Len(strConcat) > 0 Then
150 strConcat = Left(strConcat, _
Len(strConcat) - Len(pstrDelim))
160 End If
170 Concatenate = strConcat
Concatenate_Exit:
180 Exit Function
Concatenate_Error:
190 Call ErrorLog(ERL, Err.Number, Err.Description, "Concatenate", _
"modConcatenate")
200 Resume Concatenate_Exit
End Function
cn is another function which creates the connection.... I don't get the error on the cn module, but when it goes back to the concatenate function after running the cn function I get an error on line 20 which says "No value given for one or more required parameters." Error Number "-2147217904"
Here is the sql (That I have so far) for the query I am trying to create:
SELECT Format([ErrorNoteDate],"mm/dd/yyyy") AS NoteDate, tblErrorNotes.fkNCRIssueID, Concatenate("SELECT ErrorNote FROM tblErrorNotes WHERE pkNCRIssueID =" & [fkNCRIssueID]) AS ErrorDescription
FROM tblErrorNotes
GROUP BY Format([ErrorNoteDate],"mm/dd/yyyy"), tblErrorNotes.fkNCRIssueID, Concatenate("SELECT ErrorNote FROM tblErrorNotes WHERE pkNCRIssueID =" & [fkNCRIssueID])
HAVING (((tblErrorNotes.fkNCRIssueID)=[Forms]![frmErrorNotesProductType]![txtNCRIssueIDReference]));
I intend to the concatenate the date with the concatenated error notes in the query. But I can't even get the concatenation of the error notes to work.
Any ideas or suggestions would be helpful (especially if there is an easier way to achieve my goal. As well as anything as to where I am going wrong. I hope I have given enough info (as well as not too much. )