Reshmi mohankumar
Registered User.
- Local time
- Today, 06:47
- Joined
- Dec 5, 2017
- Messages
- 101
i tried to run this procedure for the column values to convert to row values and separated by ",", i had a code below. But i didn't find the way to execute this
<code>
Public Function RSFieldAsSeparatedString(ByVal fieldName As String, _
ByVal tableOrQueryName As String, _
Optional ByVal delimiter As String = "," _
) As String
' Paramter description
' fieldName = Is the name of the field containing the values
' we want in our comma separated string
' tableOrQueryName = Is the name of table or query containing the column
' criteria = The criteria to filter the data
' sortBy = An optional sort expression to sort the data
' delimiter = The delimiter used to separate the values. It defaults
' to a comma and a blank, but you can use anything you
' like there
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset
Dim ssql As String
'Dim whereCondition As String
Dim retVal As String
Set db = Application.CurrentDb
Set qdf = db.QueryDefs(tableOrQueryName)
' If there where any criteria passed to the function, we build a WHERE-condition for SQL
' If Len(criteria) > 0 Then
'whereCondition = " WHERE " & criteria
'End If
' building the complete SQL string
ssql = "Select " & fieldName & " from " & tableOrQueryName
' opening a recordset
Set rs = qdf.OpenRecordset(ssql, 1)
Do Until rs.EOF
' here we are looping through the records and, if the value is not NULL,
' concatenate the field value of each record with the delimiter
If Not IsNull(rs.Fields(0).Value) Then
retVal = retVal & Nz(rs.Fields(0).Value, "") & delimiter
End If
rs.MoveNext
Loop
' we cut away the last delimiter
retVal = Left(retVal, Len(retVal) - Len(delimiter))
' setting the return value of the function
RSFieldAsSeparatedString = retVal
' cleaning up our objects
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
</code>
here is my call code
<code>
Me.txtnums.Value = RSFieldAsSeparatedString("smsnumber", "qRY_SMS_NUMBERS")
</code>
here 'smsnumbers' datatype is shorttext in linked table, But i insert number values there
<code>
Public Function RSFieldAsSeparatedString(ByVal fieldName As String, _
ByVal tableOrQueryName As String, _
Optional ByVal delimiter As String = "," _
) As String
' Paramter description
' fieldName = Is the name of the field containing the values
' we want in our comma separated string
' tableOrQueryName = Is the name of table or query containing the column
' criteria = The criteria to filter the data
' sortBy = An optional sort expression to sort the data
' delimiter = The delimiter used to separate the values. It defaults
' to a comma and a blank, but you can use anything you
' like there
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset
Dim ssql As String
'Dim whereCondition As String
Dim retVal As String
Set db = Application.CurrentDb
Set qdf = db.QueryDefs(tableOrQueryName)
' If there where any criteria passed to the function, we build a WHERE-condition for SQL
' If Len(criteria) > 0 Then
'whereCondition = " WHERE " & criteria
'End If
' building the complete SQL string
ssql = "Select " & fieldName & " from " & tableOrQueryName
' opening a recordset
Set rs = qdf.OpenRecordset(ssql, 1)
Do Until rs.EOF
' here we are looping through the records and, if the value is not NULL,
' concatenate the field value of each record with the delimiter
If Not IsNull(rs.Fields(0).Value) Then
retVal = retVal & Nz(rs.Fields(0).Value, "") & delimiter
End If
rs.MoveNext
Loop
' we cut away the last delimiter
retVal = Left(retVal, Len(retVal) - Len(delimiter))
' setting the return value of the function
RSFieldAsSeparatedString = retVal
' cleaning up our objects
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
</code>
here is my call code
<code>
Me.txtnums.Value = RSFieldAsSeparatedString("smsnumber", "qRY_SMS_NUMBERS")
</code>
here 'smsnumbers' datatype is shorttext in linked table, But i insert number values there