Need Help in one to many relationship between columns (1 Viewer)

Nimmy.K

New member
Local time
Yesterday, 17:22
Joined
Mar 31, 2010
Messages
7
Hi,

I have a table Structure

filename AKA
12-3-09.pdf 443567
12-3-09.pdf 345678
12-3-09.pdf 456789
3-3-10.pdf 78901
filename AKA
I want to output as 12-3-09.pdf 443567,345678,456789
3-3-10.pdf 78901.

Any Help would be appreciated

Thanks!
 

Nimmy.K

New member
Local time
Yesterday, 17:22
Joined
Mar 31, 2010
Messages
7
Thanks for the reply.

I m new to access database.I have created the function in module and when i m trying to excute the query it is saying their is no contact function defined.

Function concat(image1 As String) As String

Dim mystring As String
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("Primary", Project2)

With rs
.MoveFirst
Do Until .EOF
If ![image] = image1 Then
mystring = mystring & ![AKA/HS1] & ", "
End If
.MoveNext
Loop
End With

mystring = Left(mystring, (Len(mystring) - 2))

concat = mystring

End Function

Select [image], contact([AKA/HS1]) As HS1 From [Primary]

Its saying undefined function 'contact'.
Can you please Help me out

Thanks!
 

vbaInet

AWF VIP
Local time
Today, 01:22
Joined
Jan 22, 2010
Messages
26,374
I don't think I can explain it any better as what is explained in both those links. Follow them step-by-step.
 

Nimmy.K

New member
Local time
Yesterday, 17:22
Joined
Mar 31, 2010
Messages
7
Anywaz Thankyou...
The error that i m getting is function expression not found
 

FoFa

Registered User.
Local time
Yesterday, 19:22
Joined
Jan 29, 2003
Messages
3,672
Not 100% sure mind you, but your function name and your reference of that function are different in your example.

Contact vs. Concat
 

Nimmy.K

New member
Local time
Yesterday, 17:22
Joined
Mar 31, 2010
Messages
7
Not 100% sure mind you, but your function name and your reference of that function are different in your example.

Contact vs. Concat

Hey Thanks For Correcting me,
It was a mistake when i was typing the forum.I checked out my function name n function name that i have passed in the query.
Still not resolved .Still The same error

*Undefined function Concat in expression*
 

vbaInet

AWF VIP
Local time
Today, 01:22
Joined
Jan 22, 2010
Messages
26,374
How did you put it in the query? Let's see the query.

Also did you put the code in a MODULE?
 

Nimmy.K

New member
Local time
Yesterday, 17:22
Joined
Mar 31, 2010
Messages
7
How did you put it in the query? Let's see the query.

Also did you put the code in a MODULE?

I have put the function in the module.

Option Compare Database

Public Function ConcatRelated(strField As String, strTable As String, Optional strSeparator = ",") As Variant
On Error GoTo Err_Handler
'Purpose: Generate a concatenated string of related records.
'Return: String variant, or Null if no matches.
'Arguments: strField = name of field to get results from and concatenate.
' strTable = name of a table or query.
' strWhere = WHERE clause to choose the right values.
' strOrderBy = ORDER BY clause, for sorting the values.
' strSeparator = characters to use between the concatenated values.
'Notes: 1. Use square brackets around field/table names with spaces or odd characters.
' 2. strField can be a Multi-valued field (A2007 and later), but strOrderBy cannot.
' 3. Nulls are omitted, zero-length strings (ZLSs) are returned as ZLSs.
' 4. Returning more than 255 characters to a recordset triggers this Access bug:
' http://allenbrowne.com/bug-16.html
Dim rs As DAO.Recordset 'Related records
Dim rsMV As DAO.Recordset 'Multi-valued field recordset
Dim strSql As String 'SQL statement
Dim strOut As String 'Output string to concatenate to.
Dim lngLen As Long 'Length of string.
Dim bIsMultiValue As Boolean 'Flag if strField is a multi-valued field.

'Initialize to Null
ConcatRelated = Null

'Build SQL string, and get the records.
strSql = "SELECT " & strField & " FROM " & strTable


Set rs = DBEngine(0)(0).OpenRecordset(strSql, dbOpenDynas)
'Determine if the requested field is multi-valued (Type is above 100.)
bIsMultiValue = (rs(0).Type > 100)

'Loop through the matching records
Do While Not rs.EOF
If bIsMultiValue Then
'For multi-valued field, loop through the values
Set rsMV = rs(0).Value
Do While Not rsMV.EOF
If Not IsNull(rsMV(0)) Then
strOut = strOut & rsMV(0) & strSeparator
End If
rsMV.MoveNext
Loop
Set rsMV = Nothing
ElseIf Not IsNull(rs(0)) Then
strOut = strOut & rs(0) & strSeparator
End If
rs.MoveNext
Loop
rs.Close

'Return the string without the trailing separator.
lngLen = Len(strOut) - Len(strSeparator)
If lngLen > 0 Then
ConcatRelated = Left(strOut, lngLen)
End If

Exit_Handler:
'Clean up
Set rsMV = Nothing
Set rs = Nothing
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "ConcatRelated()"
Resume Exit_Handler
End Function

This is the exact function dat i have used.

I created a new query

SELECT image, ConcatRelated("[AKA/HS1]","[Primary]")
FROM [Primary];
This the query that i have excuted.

When i am running the query i am getting

'Undefined function ConcatRelated in expression'

Thanks for looking into this
 

vbaInet

AWF VIP
Local time
Today, 01:22
Joined
Jan 22, 2010
Messages
26,374
I think you need the 3rd argument as well as an ALIAS for that field.

What is the image field? I'm hoping it's not an image? Avoid using names like that as field names.
 

Nimmy.K

New member
Local time
Yesterday, 17:22
Joined
Mar 31, 2010
Messages
7
I think you need the 3rd argument as well as an ALIAS for that field.

What is the image field? I'm hoping it's not an image? Avoid using names like that as field names.

I have passed the third argument as ALIAS but no luck.
the image field holds the images name which i m using in my WEBPAGE.

Still i m getting the same error
 

vbaInet

AWF VIP
Local time
Today, 01:22
Joined
Jan 22, 2010
Messages
26,374
You can't pass the third argument as an alias. I said to make the FIELD as an alias. Show your query as it stands.
 

Nimmy.K

New member
Local time
Yesterday, 17:22
Joined
Mar 31, 2010
Messages
7
You can't pass the third argument as an alias. I said to make the FIELD as an alias. Show your query as it stands.


This the query :
SELECT image, ConcatRelated("[AKA/HS1]","[Primary]",",")
FROM [Primary];

The third argument is anywaz declared as an optional.
 

vbaInet

AWF VIP
Local time
Today, 01:22
Joined
Jan 22, 2010
Messages
26,374
The third argument is anywaz declared as an optional.
Question: Without the third argument, how does it know which filename it needs to base the returned results on?

By the way, I didn't see any alias.
 

FoFa

Registered User.
Local time
Yesterday, 19:22
Joined
Jan 29, 2003
Messages
3,672
If you go into the builder, and functions, can you find the function listed in that?
 

Users who are viewing this thread

Top Bottom