Supress error message on FindRecord command | Newbie | | Join Date: Oct 2006
Posts: 4
| | |
I'm using the "DoCmd.FindRecord" method and it's working fine. But if there aren't any records to be found at all, I get a: "You can't use Find or Replace now" error message. How do I stop that error message from appearing?
Thank you,
Amy
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,722
| | | re: Supress error message on FindRecord command Quote:
Originally Posted by ashatzen I'm using the "DoCmd.FindRecord" method and it's working fine. But if there aren't any records to be found at all, I get a: "You can't use Find or Replace now" error message. How do I stop that error message from appearing?
Thank you,
Amy - On Error Resume Next
-
DoCmd.FindRecord ...
-
If Err > 0 Then {failed}
-
On Error GoTo 0
| | Newbie | | Join Date: Oct 2006
Posts: 4
| | | re: Supress error message on FindRecord command
That worked perfect! Thanks!! Quote:
Originally Posted by NeoPa - On Error Resume Next
-
DoCmd.FindRecord ...
-
If Err > 0 Then {failed}
-
On Error GoTo 0
| | Newbie | | Join Date: Jan 2007
Posts: 4
| | | re: Supress error message on FindRecord command
Hi,
I'm trying to put the code: -
On Error Resume Next
-
DoCmd.FindRecord ...
-
If Err > 0 Then {failed}
-
On Error GoTo 0
-
in this code - Dim studentRef As String
-
Dim search As String
-
'variables a usarse para guardarar los valores
-
'verifica si el campo text_barcode esta vacio
-
If IsNull(Me![text_BuscarEst]) Or (Me![text_BuscarEst]) = "" Then
-
MsgBox "¡Por favor ingrese un valor!", vbOKOnly, "Búsqueda inválida"
-
Me![text_BuscarEst].SetFocus
-
Exit Sub
-
End If
-
DoCmd.ShowAllRecords
-
DoCmd.GoToControl ("ID")
-
DoCmd.FindRecord Me!text_BuscarEst
-
-
ID.SetFocus
-
studentRef = ID.Text
-
text_BuscarEst.SetFocus
-
search = text_BuscarEst.Text
-
-
If studentRef = text_BuscarEst Then
-
MsgBox "Se encontró el #estudiante " & text_BuscarEst, vbOKOnly, "¡Felicidades!"
-
ID.SetFocus
-
txtSearch = ""
-
Else
-
MsgBox "Match Not Found For: " & text_BuscarEst & " - Please Try Again.", _
-
, "Invalid Search Criterion!"
-
text_BuscarEst.SetFocus
-
-
-
End If
The problem is that I don't know in wich part I have to put the code of the routine error to prevent the "You can't use find or replace now" error message. |  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,722
| | | re: Supress error message on FindRecord command
Try this version : - Dim studentRef As String
-
Dim search As String
-
'variables a usarse para guardarar los valores
-
'verifica si el campo text_barcode esta vacio
-
If IsNull(Me![text_BuscarEst]) Or (Me![text_BuscarEst]) = "" Then
-
MsgBox "¡Por favor ingrese un valor!", vbOKOnly, "Búsqueda inválida"
-
Me![text_BuscarEst].SetFocus
-
Exit Sub
-
End If
-
DoCmd.ShowAllRecords
-
DoCmd.GoToControl ("ID")
-
On Error Resume Next
-
DoCmd.FindRecord Me!text_BuscarEst
-
'You need to update this (following) line
-
If Err > 0 Then {failed}
-
On Error GoTo 0
-
-
ID.SetFocus
-
studentRef = ID.Text
-
text_BuscarEst.SetFocus
-
search = text_BuscarEst.Text
-
-
If studentRef = text_BuscarEst Then
-
MsgBox "Se encontró el #estudiante " & text_BuscarEst, vbOKOnly, "¡Felicidades!"
-
ID.SetFocus
-
txtSearch = ""
-
Else
-
MsgBox "Match Not Found For: " & text_BuscarEst & " - Please Try Again.", _
-
, "Invalid Search Criterion!"
-
text_BuscarEst.SetFocus
-
-
-
End If
Remember to update the line in bold.
| | Newbie | | Join Date: Jan 2007
Posts: 4
| | | re: Supress error message on FindRecord command
Thank for your help the code work very good. I have a question, you don't wich book is a good starting in MS access with code examples.
Rafael
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,722
| | | re: Supress error message on FindRecord command
Although I don't have a lot of personal experience of such things, I believe Access For Dummies and other titles in the series are supposed to be quite good.
|  | Similar Microsoft Access / VBA bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,439 network members.
|