I have the code below to query an SQL Server Backend database
The first part uses a public function (populatelst) in a class module (clsCables) to query the database and return an ADODB Recordset to the rsPopLst Recordset in this module.
If I assign the rsPopLst recordset to the RecordSource property of the ListBox (lst). all is fine except that one field in the recorset is held in the database unformatted and I want it displayed formatted.
To do this I create another recordset (rsNewLst), add fields, and then populate this recordset from the rsPopLst recordset (tne nn funtion converts nulls to blanks and the cableref function formats the data). However when I use this new recordset to populate the listbox no data is displayed (the field names are however displayed as headers).
I know the rsNewLst recordset contains the appropriate data (I've checked in the immediate window). I've also found the listbox contains the appropriate number of of rows and that every row contains only null values.
I can't use a string constructed from the data because there is too much of it.
I would appreciate if someone could point me in the right direction.
Thanks
The Code****************************
Private Sub Form_Open(Cancel As Integer)
Dim c As New clsCables
Dim rsPopLst As New ADODB.Recordset
Dim rsNewLst As New ADODB.Recordset
c.CabLetter = "AR" ' Keep the returned data small for testing
Set rsPopLst = c.PopulateLst
rsNewLst.Fields.Append "UniqueID", adVarChar, 9, adFldUpdatable
rsNewLst.Fields.Append "WBox", adVarChar, 50, adFldUpdatable
rsNewLst.Fields.Append "Room", adVarChar, 50, adFldUpdatable
rsNewLst.Fields.Append "Description", adVariant, 50, adFldUpdatable
rsNewLst.Fields.Append "Comment", adVariant, 100, adFldUpdatable
rsNewLst.Fields.Append "CableNo", adVariant, 50, adFldUpdatable
rsNewLst.Fields.Append "DrawingNO", adVarChar, 50, adFldUpdatable
rsNewLst.Fields.Append "LinkRef", adVarChar, 15, adFldUpdatable
rsNewLst.Open
Do While Not rsPopLst.EOF
rsNewLst.AddNew
rsNewLst!UniqueID = nn(Trim(rsPopLst!UniqueID))
rsNewLst!wbox = nn(Trim(CableRef(rsPopLst!UniqueID)))
rsNewLst!Room = nn(Trim(rsPopLst!Room))
rsNewLst!Description = nn(Trim(rsPopLst!Description))
rsNewLst!Comment = nn(Trim(rsPopLst!Comment))
rsNewLst!CableNo = nn(Trim(rsPopLst!CableNo))
rsNewLst!DrawingNo = nn(Trim(rsPopLst!DrawingNo))
rsNewLst!LinkRef = nn(Trim(rsPopLst!LinkRef))
rsNewLst.Update
rsPopLst.MoveNext
Loop
lst.RowSourceType = "Table/Query"
Set lst.Recordset = Nothing
Set lst.Recordset = rsNewLst
End Sub
The first part uses a public function (populatelst) in a class module (clsCables) to query the database and return an ADODB Recordset to the rsPopLst Recordset in this module.
If I assign the rsPopLst recordset to the RecordSource property of the ListBox (lst). all is fine except that one field in the recorset is held in the database unformatted and I want it displayed formatted.
To do this I create another recordset (rsNewLst), add fields, and then populate this recordset from the rsPopLst recordset (tne nn funtion converts nulls to blanks and the cableref function formats the data). However when I use this new recordset to populate the listbox no data is displayed (the field names are however displayed as headers).
I know the rsNewLst recordset contains the appropriate data (I've checked in the immediate window). I've also found the listbox contains the appropriate number of of rows and that every row contains only null values.
I can't use a string constructed from the data because there is too much of it.
I would appreciate if someone could point me in the right direction.
Thanks
The Code****************************
Private Sub Form_Open(Cancel As Integer)
Dim c As New clsCables
Dim rsPopLst As New ADODB.Recordset
Dim rsNewLst As New ADODB.Recordset
c.CabLetter = "AR" ' Keep the returned data small for testing
Set rsPopLst = c.PopulateLst
rsNewLst.Fields.Append "UniqueID", adVarChar, 9, adFldUpdatable
rsNewLst.Fields.Append "WBox", adVarChar, 50, adFldUpdatable
rsNewLst.Fields.Append "Room", adVarChar, 50, adFldUpdatable
rsNewLst.Fields.Append "Description", adVariant, 50, adFldUpdatable
rsNewLst.Fields.Append "Comment", adVariant, 100, adFldUpdatable
rsNewLst.Fields.Append "CableNo", adVariant, 50, adFldUpdatable
rsNewLst.Fields.Append "DrawingNO", adVarChar, 50, adFldUpdatable
rsNewLst.Fields.Append "LinkRef", adVarChar, 15, adFldUpdatable
rsNewLst.Open
Do While Not rsPopLst.EOF
rsNewLst.AddNew
rsNewLst!UniqueID = nn(Trim(rsPopLst!UniqueID))
rsNewLst!wbox = nn(Trim(CableRef(rsPopLst!UniqueID)))
rsNewLst!Room = nn(Trim(rsPopLst!Room))
rsNewLst!Description = nn(Trim(rsPopLst!Description))
rsNewLst!Comment = nn(Trim(rsPopLst!Comment))
rsNewLst!CableNo = nn(Trim(rsPopLst!CableNo))
rsNewLst!DrawingNo = nn(Trim(rsPopLst!DrawingNo))
rsNewLst!LinkRef = nn(Trim(rsPopLst!LinkRef))
rsNewLst.Update
rsPopLst.MoveNext
Loop
lst.RowSourceType = "Table/Query"
Set lst.Recordset = Nothing
Set lst.Recordset = rsNewLst
End Sub