tags:

views:

324

answers:

1

How can I handle the case when the following statement returns nothing, i.e. a non-existing record?

Form1.data1.RecordSource = "SELECT * " _
                         & "FROM Table " _
                         & "WHERE Column1 = " & txtSomeTextField.Text & ""
Form1.data1.Refresh

Edit: The error I get is: Run-time error '3021': No current record

+5  A: 

Check for EOF And BOF of the record set ...

If Not rs.EOF And Not rs.BOF Then
   ' You have results
End If
JP Alioto
If I do the check before the refresh then the recordset has not been refreshed.If I do the check after the refresh then I can't catch the error.
Yes, do your query first, place the results into a new RecordSet object, check the RecordSet object and then set your Form property using your local variable.
JP Alioto
That is the accepted best practice method.
MaSuGaNa