title: vba - Run time error 3021 - EOF or BOF is true or the current record has been deleted
body: <p>I have written the bellow code, but i am getting an error at <code>getIDKategori = rs!id_kategori</code></p>
  
  <pre><code>Public Function getIDKategori(ByVal nama As String) As Integer
    Dim rs As New ADODB.Recordset
    Set rs.ActiveConnection = CurrentProject.Connection
    rs.Open "SELECT kategori.id_kategori FROM kategori WHERE nama_kategori='" &amp; nama &amp; "';"
  
    getIDKategori = rs!id_kategori
    rs.Close
    Set rs = Nothing
  End Function
  </code></pre>