Link to home
Start Free TrialLog in
Avatar of CipherIS
CipherISFlag for United States of America

asked on

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
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Can you post the code instead of an image.

mx
Try just this:

x=0
Do Until rs.EOF
    Me.varAircraftType.AddItem = rs(x).Value
    x=x+1  
Loop
Avatar of CipherIS

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial