MS Access VBA Recordset Error

I wrote this code below.  The recordset contains data (2 records).  When walking through the recordset rs(0).value contains data but when it gets to rs(1).value it errors out.

Any idea how to resolve?
RecordsetError.JPG
LVL 1
CipherISAsked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
Is this what you are trying to do ?

Do
    Me.varAircraftType.AddItem = rs![Aircraft Type]
    rs.MoveNext
Loop  Until rs.EOF
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Can you post the code instead of an image.

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Try just this:

x=0
Do Until rs.EOF
    Me.varAircraftType.AddItem = rs(x).Value
    x=x+1  
Loop
0
 
CipherISAuthor Commented:
That didn't work either
Dim x As Integer
Dim db As dao.Database
Dim rs As dao.Recordset
Dim sSQL As String
    
sSQL = "SELECT [Aircraft Type] FROM tblAircraft ORDER BY [Aircraft Type]"
    
Me.varAircrafttype.AddItem ("All")
            
Set db = CurrentDb
Set rs = db.OpenRecordset(sSQL)

x = 0
If Not (rs.EOF) Then
   Do Until rs.EOF
      Me.varAircrafttype.AddItem (rs(x).Value)
      x = x + 1
   Loop
End If

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.