alastair69
Registered User.
- Local time
- Today, 08:58
- Joined
- Dec 21, 2004
- Messages
- 560
I hope you all have recovered from Christmas and the New Year.
I have the following code and would like a way of copping with null values in a table the code i have was constructed by Raskew.
The code is to list the Rooms in one row like:-
1/055 , Above 1/198 , G/116 , G/134 , G/179
I would also lie the list above to show like this:-
1/055, Above 1/198, G/116, G/134, G/179
The Code that is used is as follows:-
Function StringEm(ptblName As String, pfldName As String, _
Optional xx As String) As String
'**********************************************************
'Purpose: Build a string of field values
' displayed in a record set
'Coded by: raskew
'To test: From Northwind debug window
' ? StringEm("Employees", "LastName", ", ")
'**********************************************************
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim strhold As String
Dim n As Integer
Dim i As Integer
xx = IIf(xx = " ", " ", xx)
Set db = CurrentDb
' strSQL = "SELECT distinct " & pfldName & " FROM " & ptblName _
' & " ORDER BY " & pfldName & "; "
strSQL = "SELECT distinct " & pfldName & " FROM " & ptblName & "; "
Set rs = db.OpenRecordset(strSQL)
rs.MoveLast
n = rs.RecordCount
rs.MoveFirst
If n > 0 Then
For i = 1 To n
strhold = strhold & rs(pfldName) & xx
rs.MoveNext
Next i
strhold = Left(strhold, Len(Trim(strhold)) - Len(Trim(xx)))
StringEm = strhold
End If
rs.Close
db.Close
Set db = Nothing
End Function
Thanks Inadvance
Alastair
UPDATE:
*******************************RESOLVED THANKS TO david.brent & BAT17*****************************
I have the following code and would like a way of copping with null values in a table the code i have was constructed by Raskew.
The code is to list the Rooms in one row like:-
1/055 , Above 1/198 , G/116 , G/134 , G/179
I would also lie the list above to show like this:-
1/055, Above 1/198, G/116, G/134, G/179
The Code that is used is as follows:-
Function StringEm(ptblName As String, pfldName As String, _
Optional xx As String) As String
'**********************************************************
'Purpose: Build a string of field values
' displayed in a record set
'Coded by: raskew
'To test: From Northwind debug window
' ? StringEm("Employees", "LastName", ", ")
'**********************************************************
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim strhold As String
Dim n As Integer
Dim i As Integer
xx = IIf(xx = " ", " ", xx)
Set db = CurrentDb
' strSQL = "SELECT distinct " & pfldName & " FROM " & ptblName _
' & " ORDER BY " & pfldName & "; "
strSQL = "SELECT distinct " & pfldName & " FROM " & ptblName & "; "
Set rs = db.OpenRecordset(strSQL)
rs.MoveLast
n = rs.RecordCount
rs.MoveFirst
If n > 0 Then
For i = 1 To n
strhold = strhold & rs(pfldName) & xx
rs.MoveNext
Next i
strhold = Left(strhold, Len(Trim(strhold)) - Len(Trim(xx)))
StringEm = strhold
End If
rs.Close
db.Close
Set db = Nothing
End Function
Thanks Inadvance
Alastair
UPDATE:
*******************************RESOLVED THANKS TO david.brent & BAT17*****************************
Last edited: