Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling FilterMyForm 1

Status
Not open for further replies.

NeilT123

Technical User
Jan 6, 2005
302
GB
Hi to all. It has been a long day and I am afraid my brain is fried so can I ask for the help of the forum?

On my form I have 26 command buttons A - Z and OnClick =FilterMyForm()

The code behind FilterMyForm is

Code:
' The filtering on this form is in two parts, the "is like" and the "begins with".
' The "is like" is linked to Search2 which is an invisible text box in the form and "begins with" is linked to Search3.
' Search2 and 3 are criteria in the query for the subform.
' Search2 is updated via direct code in the "Change" part of the search text box and Search3 is updated via the code
' in FilterMyForm. The FilterMyForm could be direct coded into the onClick of the A-Z buttons but the
' Private Function negates the need for multiple coding

Private Function FilterMyForm()

' clear any criteria in the visible search box Search and hidden search box Search2.
Me.Search = ""
Me.Search2 = ""
' save the variable strFilter and apply it to Search3
Dim strFilter As String
    strFilter = Screen.ActiveControl.Name
    Search3.Value = strFilter
    Me.frmIfSoilAnalResults.Requery
    Me.frmIfSoilAnalResults.Form.Recordset.MoveFirst
End Function

I have Today, for the first time in several years of using this form got the error message

"The expression On Click you entered as the event property setting produced the following error:No Current Record"

I realise there is no error handling in my code and have tried to set up an error handler but to be honest am out of my depth. Can anyone show me how to set up an error handler to deal with the No Current Record issue.

Thanks
 
How are ya NeilT123 . . .

Try this:
Code:
Private Function FilterMyForm()
   Dim [COLOR=#204A87][b]frm[/b][/color] As Form, strFilter As String
   
   Set [COLOR=#204A87][b]frm[/b][/color] = Me.frmIfSoilAnalResults.Form
   Me.Search = ""
   Me.Search2 = ""
   
   strFilter = Screen.ActiveControl.Name
   Search3.Value = strFilter
   
   [COLOR=#204A87][b]frm[/b][/color].Requery
   DoEvents
   
   [COLOR=#4E9A06]'Detect if recordset is empty[/color]
   If [COLOR=#204A87][b]frm[/b][/color].Recordset.RecordCount > 0 Then
      [COLOR=#204A87][b]frm[/b][/color].Recordset.MoveFirst
   Else
      magbox "No records in srbForm! . . ."
   End If
   
   Set [COLOR=#204A87][b]frm[/b][/color] = Nothing
   
End Function

Your Thoughts? . . .

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi AceMan1, after a break and some food I had another look at my code and was able to get error handling working which dealt with the error message and stopped the form freezing but in my code the msgbox was inconsistent.

Then I received your code which is clean, works a treat and is much better as it prevents the error from happening rather than dealing with the error message.

Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top