Results 1 to 2 of 2
  1. #1
    bjelinski is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    13

    Search doesnt find record and opens debug message

    Dear all,



    I have a form, where I removed the “default record counter at the bottom of the page” and added a custom made (the code is shown below)! But however I have a problem now, because when I use my search, and if there was a mistake in search I get a debug message “Run time error 3021: No current record. “ and it marks my “.MoveFirst” part of my custom made record counter. I would like to bypass the debug thing and just leave message box that there is no record!

    Any clue how to do this!

    Thanks in advance!


    CUSTOM MADE record counter (added a unbounded text box with code on current event) :

    Private Sub Form_Current()
    'Show the result of the record count in the text box (txtRecordNo)
    Dim lngCount As Long
    Set rst = Me.RecordsetClone

    With rst
    .MoveFirst
    .MoveLast
    lngCount = .RecordCount
    End With

    Me.txtRecordNo = "Customer " & Me.CurrentRecord & " of " & lngCount
    End Sub

    SEARCH CODE :

    Private Sub cmdSearch_Click()

    If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
    MsgBox "You must select a field to search."

    ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
    MsgBox "You must enter a search string."

    Else

    'Generate search criteria
    GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"

    'Filter frmCustomers based on search criteria
    Form_frmSales.RecordSource = "select * from qry_filter_current_user where " & GCriteria
    Form_frmSales.Caption = "Customers (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"

    'Close frmSearch
    DoCmd.Close acForm, "frmSearch"

    MsgBox "Results have been filtered."

    End If

    End Sub

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you may check recordcount, if recordcount is 0, do it in other way.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Search records and return message.
    By sYn in forum Programming
    Replies: 4
    Last Post: 01-07-2011, 11:21 PM
  2. Clicking on label opens up new record
    By swimmermx in forum Forms
    Replies: 2
    Last Post: 07-20-2010, 03:58 PM
  3. Error message and How do I find the "value Field" ?
    By createdwithfire in forum Forms
    Replies: 1
    Last Post: 11-05-2009, 12:26 PM
  4. program find button to search whole table
    By sammer021486 in forum Programming
    Replies: 2
    Last Post: 10-01-2009, 06:36 AM
  5. My subform doesnt refresh????? HELP!
    By LiamMurphy in forum Forms
    Replies: 1
    Last Post: 03-09-2006, 09:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums