Populate Userform Listbox with Access values
On 5 Apr, 15:49, "merjet" wrote:
Here is a working example.
Private Sub UserForm_Activate()
Dim db As Database
Dim rs As Recordset
Dim Sql As String
Set db = OpenDatabase("C:\temp\db1.mdb")
Sql = "SELECT * FROM Table1 WHERE " _
& "Name = " & Chr(34) & "Smith" & Chr(34)
Set rs = db.OpenRecordset(Sql)
With rs
If Not .BOF Then .MoveFirst
While Not .EOF
With ListBox1
.AddItem rs("Name")
.List(.ListCount - 1, 1) = rs("Age")
.List(.ListCount - 1, 2) = rs("SDate")
.List(.ListCount - 1, 3) = rs("Pay")
End With
.MoveNext
Wend
End With
Set rs = Nothing
db.Close
Set db = Nothing
End Sub
Hth,
Merjet
Thanks Merjet,
I have used
With rs
If Not .BOF Then .MoveFirst
While Not .EOF
With ListBox1
.AddItem rs("Name")
.List(.ListCount - 1, 1) = rs("Age")
.List(.ListCount - 1, 2) = rs("SDate")
.List(.ListCount - 1, 3) = rs("Pay")
End With
.MoveNext
Wend
works fine, i now need to be able to update the same recordset feilds
on a seperate userform, do you have any exampleas of this please??
|