Go Back   DeveloperBarn Forums > Databases > Microsoft Access

Sponsored Links

Discuss "Concatenation of Column Data function" in the Microsoft Access forum.

Microsoft Access - Microsoft Access is a database for small to medium applications. Learn tips and tricks and best database practices here.


Closed Thread « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old March 25th, 2008, 06:53 AM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 93
Thanks: 6
Thanked 23 Times in 18 Posts
Rep Power: 1
AOG123 is on a distinguished road

Awards Showcase
Microsoft Access 
Total Awards: 1

Default Concatenation of Column Data function

Copy the following into a Module,

Code:
Public Function Conc(Fieldx, Identity, Value, Source) As Variant
  Dim cnn As ADODB.Connection
  Dim rs As ADODB.Recordset
  Dim SQL As String
  Dim vFld As Variant
  
  Set cnn = CurrentProject.Connection
  Set rs = New ADODB.Recordset
  vFld = Null
  
  SQL = "SELECT [" & Fieldx & "] as Fld" & _
        " FROM [" & Source & "]" & _
        " WHERE [" & Identity & "]='" & Value & "'"
  
  ' open recordset.
  rs.Open SQL, cnn, adOpenForwardOnly, adLockReadOnly
  
  ' concatenate the field.
  Do While Not rs.EOF
    If Not IsNull(rs!Fld) Then
      vFld = vFld & ", " & rs!Fld
    End If
    rs.MoveNext
  Loop
  ' remove leading comma and space.
  vFld = Mid(vFld, 3)
  
  Set cnn = Nothing
  Set rs = Nothing
  
  ' return concatenated string.
  Conc = vFld
End Function
Then call the fucntion in a query.-

Code:
SELECT Conc("ConcatField","Byfield",[Byfield],"Table/Query") AS Field
FROM Table/Query;
Thanks

AOG
__________________
If i helped you, make me famous by clicking the
Sponsored Links
Closed Thread

  DeveloperBarn Forums > Databases > Microsoft Access

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 06:26 PM.



Content Relevant URLs by vBSEO 3.2.0