Link to home
Start Free TrialLog in
Avatar of Peter Brown
Peter Brown

asked on

Runtime Error 2015

Hi All,

I have a Run-time Error '2105' (You can't go to the specified record) in the event builder.
This is my code

    Option Compare Database
   




Private Sub Command123_Click()

End Sub



    Private Sub Form_Load()
   
    Dim str As String
    Dim db As Database
    Dim rs As DAO.Recordset
    Dim sSQL As String
   
    sSQL = "SELECT distinct(ID)  FROM tblMembers"
    Set db = CurrentDb
    Set rs = db.OpenRecordset(sSQL)
    MemberID.SetFocus
    MemberID.RowSource = ""
      Do While Not rs.EOF
       MemberID.AddItem (rs!ID)
        rs.MoveNext
       Loop
       
    Set rs = Nothing
    Set db = Nothing
       
   
    End Sub
   

    Private Sub MemberID_Change()
    Dim strID As Integer
    Dim strName As String
   
    strID = CInt(MemberID.Text)
   
    Dim db As Database
    Dim rs As DAO.Recordset
    Dim sSQL As String
    sSQL = "SELECT *  FROM tblMembers s WHERE s.id = " & strID
    Set db = CurrentDb
    Set rs = db.OpenRecordset(sSQL)

    If rs.RecordCount > 0 Then
     txtFullName.Value = rs!Title & " " & rs!Fname & " " & rs!Mname & " " & rs!SurName
    Else
       txtFullName.Value = "Record Not found"
    End If
    Set rs = Nothing
    Set db = Nothing

End Sub

Thank you
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

there could be problem in your codes below

>>  MemberID.SetFocus
    MemberID.RowSource = ""

try remove the code :

  MemberID.SetFocus
   
and see if that worked?
any further assistance is needed here?
is your rowsourcetype set to Value List?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.