We help IT Professionals succeed at work.

Filling a textbox-array with recordset's value's

HeN_da_MaN
HeN_da_MaN asked
on
I'm making an accessed-based database-app.
I wanted to make an array from textboxes, where the index is not known in front.
I made an array with 5 textboxes, (would like to be able to do this using ReDim Preserve maybe?) but my biggest problem is that EndOfFile doesn't work in my Loop.
This code I'm using (the filter property was a desparate attempt, I know I can lose it):

 Private Function Maak_txtBox()
Dim i As Integer
   
   Set RecSet = New ADODB.Recordset
   With RecSet
      .ActiveConnection = con
      .CursorLocation = adUseClient
      .CursorType = adOpenStatic
      .LockType = adLockReadOnly
      .Open "SELECT * FROM taalvaardigheid tv"    '****(Comment)'WHERE trainee_id =" & intZoek
      .Filter = "trainee_id =" & intZoek
      For i = 0 To .EOF
         txtTaal(i).Visible = True
         txtTaal(i).Text = .Fields("taal").Value
         .MoveNext
      Next 'i
   End With

End Function


Thanks in advance
Hen
Comment
Watch Question

I know that in Access after the open, .RecordCount holds the total records.  If it works in VB, you could ReDim with that value.

Author

Commented:
I would like to thank you, this simple but effective solution was completely overseen by me.
although now I really would like to know how to make an array (of textboxes) for which I don't want to declare the number of the index or draw more than 1 textbox on my form,
can you help me?
I found an example that may help you:
http://www.mvps.org/vbnet/index.html?code/network/isdestinationreachable.htm

Page down to the Heading 'Form Code'.  In the example, you may want to replace the:
TotalRequired = 4
with:
TotalRequired = .RecordCount

See if that sends you on the right track.

dill

Author

Commented:
Thank you!
I think now I will have solved my problems.
So maybe I can help you next time,

Thanks again
Hen

Commented:
Yes sir

.EoF is a logic value states that we reached EOF

1-
for ... Next needs    .RecordCount

2 -
U can use

Do until .EOF
    .
    .
    .
   I = I +1
Loop



Instead of for next
Hen,

No problem.  Anytime  ;)

dill

Explore More ContentExplore courses, solutions, and other research materials related to this topic.