0

I have a table with a teamName and in it i have names. I am trying to now get. all the names in Team1 to display in textbox1 to say 10. But its only returning the first name in the table.

dbPath = Sheets("Info").Range("a3").Value

CE.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath

'Getting Data from database
RE.Open "SELECT * FROM GetCrew Where CrewName ='" & Me.cmbCrewName & "'",CE, adOpenStatic

RE.MoveFirst

'Populating text box with data
Sheets("sheet3").Range("N9").Value = RE("EmpName")

so Textbox1 = John Doe textbox2 = steve and so on

arun v
  • 852
  • 7
  • 19
JvN88
  • 21
  • 2

1 Answers1

0

When you open a recordset you are at the first row of the data. You need to move through the records using the .MoveNext method. So

'Getting Data from database
RE.Open "SELECT * FROM GetCrew Where CrewName ='" & Me.cmbCrewName & "'",CE, adOpenStatic
'RE.MoveFirst   'strictly not needed, you always open at the first record

Dim r as range
set r = Sheets("sheet3").Range("N9")

Do 'begin loop
     r.Value = RE("EmpName")
     set r = r.offset(1,0) 'move pointer down one cell
     RE.MoveNext  'move recordset pointer down one
Loop Until RE.EOF  'keep goimng until End Of File in dataset
Harassed Dad
  • 4,669
  • 1
  • 10
  • 12