I create access queries from design view frequently but have just started working with code. I have a simple query that returns something like this.
ID DSM_IV
1 Autism Spectrum Disorder
1 Communication Disorder (Includes NOS and Unspecified)
2 Reactive Attachment Disorder (RAD)
3 Anxiety Disorder (Includes Other Specified/Unspecified/NOS)
3 Disruptive Mood Dysregulation Disorder
3 Pica
3 PTSD (Posttraumatic Stress Disorder)
ID is a unique identifier and DSMIV the data I want to combine by ID. I have found multiple modules on the net that do this but don't seem to for me.
First, what does the "DAO" in the following text mean? "Dim db As DAO.Database". All the functions I got from the net break here when I try to compile.
Second, there is the possibility of returning up to 450 or so characters in the combined field. Will this create a problem?
Third, below is one of the shortest things I found. How, do I change this work in my case?
ID DSM_IV
1 Autism Spectrum Disorder
1 Communication Disorder (Includes NOS and Unspecified)
2 Reactive Attachment Disorder (RAD)
3 Anxiety Disorder (Includes Other Specified/Unspecified/NOS)
3 Disruptive Mood Dysregulation Disorder
3 Pica
3 PTSD (Posttraumatic Stress Disorder)
ID is a unique identifier and DSMIV the data I want to combine by ID. I have found multiple modules on the net that do this but don't seem to for me.
First, what does the "DAO" in the following text mean? "Dim db As DAO.Database". All the functions I got from the net break here when I try to compile.
Second, there is the possibility of returning up to 450 or so characters in the combined field. Will this create a problem?
Third, below is one of the shortest things I found. How, do I change this work in my case?
Code:
Option Compare Database
Public Function fMakeCommaDelimited() As String
Dim strTemp() As String
Dim rs As ADODB.Recordset
Dim strSql As String
Dim i As Long
Dim lngRecCount As Long
Set rs = New ADODB.Recordset
strSql = "SELECT User_ID From YourTable;" 'Change the fieldname and table name to yours.
With rs
.ActiveConnection = CurrentProject.Connection
.Source = strSql
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockReadOnly
.Open options:=adCmdText
lngRecCount = .RecordCount
ReDim strTemp(lngRecCount - 1)
Do Until .EOF
strTemp(i) = !User_ID
.MoveNext
i = i + 1
Loop
.Close
End With
Set rs = Nothing
fMakeCommaDelimited = Join(strTemp, ",")
End Function
Last edited: