Hello, I have a database through which I want want to be able to search for range of records based on the date criteria. But the challenge I have is that if the starting date does not exist in the database, it gives me an EOF/BOF error.
To illustrate my challenge, lets say i have this database table
ID Date comment 1 01/01/14 Blanchard 2 14/01/14 Shall 3 22/02/14 Will 4 10/03/14 Jeff 5 14/03/14 Raymond 6 20/03/14 Bryan 7 26/03/14 Smith
if i enter the search criteria search for records where Date > 10/03/14, I get results from the database
But if i want to search for all records of what happened in march and I say search for records where Date > 01/03/14, i get the EOF/BOF error
See code below
I'm wondering, is it a syntax/keyword issue??? Just trying to figure out what i'm doing wrong.Private Sub showAfter() frmDate.Show Dim fPath As String Dim conn As ADODB.Connection Dim rs As ADODB.Recordset Dim rst As ADODB.Recordset Dim new_field As ADODB.Field Dim txt As String Dim new_range As Range Dim timer As Date timer = frmDate.dtpSelect.Value ActiveDocument.Tables(3).Cell(1, 3).Range.Text = "Showing all comments before " & timer fPath = ThisDocument.Path Set conn = New ADODB.Connection conn.Mode = adModeRead conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & fPath & "\Dbase.mdb" conn.Open Set rs = conn.Execute( _ "SELECT ID, cmtComment " & _ "FROM timeComments WHERE cmtDate > # " & timer & " # ORDER BY ID DESC") If rs.RecordCount <> 0 Then txt = txt & rs.GetString( _ ColumnDelimeter:=vbTab, _ RowDelimeter:="", _ NullExpr:="<null>") rs.Close conn.Close Set new_range = ActiveDocument.Tables(3).Cell(2, 1).Range With ActiveDocument.Tables(3).Cell(2, 1).Range .Delete .InsertAfter txt End With With ActiveDocument.Tables(3).Cell(1, 3).Range .Delete .Text = "Showing comments before - " & timer End With Else Exit Sub End If End Sub
Need help guys......