With that change over i now get:
Compile Error: Invalid use of New Keyword on line "Set rs = New Recordset"
Main Topics
Browse All TopicsAny idea how i would populate the contents of a ListView control with the results of an Sql String?
example:
Function PopulateListView(Sql As String, LV As Object)
Usage:
PopulateListView("Select * from Student_T Where StudentId = 5607423", Me!StudentListView)
I had an exmaple of this, but it would only work in and MDB if anyone would like to update it to code that would work with and ADP that would be great. (although it wouldnt take SQL only a Table/Query Name).
MDB CODE:
Option Explicit
Function FillList(Domain As String, LV As Object) As Boolean
'=========================
' Purpose: to fill a ListView control with data from a table or
' query
' Arguments: a Domain which is the name of the table or query, and
' a ListView control object
' Returns: A Boolean value to indicate if the function was
' successful
'=========================
Dim db As Database, rs As Recordset
Dim intTotCount As Integer
Dim intCount1 As Integer, intCount2 As Integer
Dim colNew As ColumnHeader, NewLine As ListItem
On Error GoTo Err_Man
' Clear the ListView control.
LV.ListItems.Clear
LV.ColumnHeaders.Clear
' Set Variables.
Set db = CurrentDb
Set rs = db.OpenRecordset(Domain)
' Set Column Headers.
For intCount1 = 0 To rs.Fields.Count - 1
Set colNew = LV.ColumnHeaders.Add(, , rs(intCount1).Name)
Next intCount1
LV.View = 3 ' Set View property to 'Report'.
' Set Total Records Counter.
rs.MoveLast
intTotCount = rs.RecordCount
rs.MoveFirst
' Loop through recordset and add Items to the control.
For intCount1 = 1 To intTotCount
If IsNumeric(rs(0).Value) Then
Set NewLine = LV.ListItems.Add(, , Str(rs(0).Value))
Else
Set NewLine = LV.ListItems.Add(, , rs(0).Value)
End If
For intCount2 = 1 To rs.Fields.Count - 1
NewLine.SubItems(intCount2
Next intCount2
rs.MoveNext
Next intCount1
Exit Function
Err_Man:
' Ignore Error 94 which indicates you passed a NULL value.
If Err = 94 Then
Resume Next
Else
' Otherwise display the error message.
MsgBox "Error: " & Err.Number & Chr(13) & _
Chr(10) & Err.Description
End If
End Function
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I did actually have the DAO refernce set, but i have removed it, as thats what someone else instructed me to do, but removing it didn't help, however changing it to Set rs = New ADODB.Recordset did work :)
this will do for now, but if you have any better ideas on how this can be done please let me know :)
Business Accounts
Answer for Membership
by: LPurvisPosted on 2007-02-20 at 20:26:17ID: 18576272
I don't see anything in there that would prevent a direct change over with the following alteration.
adOpenStatic, adLockReadOnly
The top section of
Dim db As Database, rs As Recordset
Dim intTotCount As Integer
Dim intCount1 As Integer, intCount2 As Integer
Dim colNew As ColumnHeader, NewLine As ListItem
On Error GoTo Err_Man
' Clear the ListView control.
LV.ListItems.Clear
LV.ColumnHeaders.Clear
' Set Variables.
Set db = CurrentDb
Set rs = db.OpenRecordset(Domain)
to
Dim rs As Recordset
Dim intTotCount As Integer
Dim intCount1 As Integer, intCount2 As Integer
Dim colNew As ColumnHeader, NewLine As ListItem
On Error GoTo Err_Man
' Clear the ListView control.
LV.ListItems.Clear
LV.ColumnHeaders.Clear
' Set Variables.
Set rs = New Recordset
rs.Open "SELECT * FROM [" & Domain & "]", CurrentProject.Connection,