Connecting Tech Pros Worldwide Forums | Help | Site Map

Supress error message on FindRecord command

Newbie
 
Join Date: Oct 2006
Posts: 4
#1: Oct 31 '06
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

NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#2: Oct 31 '06

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

Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2. DoCmd.FindRecord ...
  3. If Err > 0 Then {failed}
  4. On Error GoTo 0
Newbie
 
Join Date: Oct 2006
Posts: 4
#3: Oct 31 '06

re: Supress error message on FindRecord command


That worked perfect! Thanks!!

Quote:

Originally Posted by NeoPa

Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2. DoCmd.FindRecord ...
  3. If Err > 0 Then {failed}
  4. On Error GoTo 0

Newbie
 
Join Date: Jan 2007
Posts: 4
#4: Jan 30 '07

re: Supress error message on FindRecord command


Hi,

I'm trying to put the code:
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2. DoCmd.FindRecord ...
  3. If Err > 0 Then {failed}
  4. On Error GoTo 0
  5.  
in this code
Expand|Select|Wrap|Line Numbers
  1. Dim studentRef As String
  2.     Dim search As String
  3. 'variables a usarse para guardarar los valores
  4. 'verifica si el campo text_barcode esta vacio
  5.     If IsNull(Me![text_BuscarEst]) Or (Me![text_BuscarEst]) = "" Then
  6.         MsgBox "¡Por favor ingrese un valor!", vbOKOnly, "Búsqueda inválida"
  7.         Me![text_BuscarEst].SetFocus
  8.     Exit Sub
  9. End If   
  10.     DoCmd.ShowAllRecords
  11.     DoCmd.GoToControl ("ID")
  12.     DoCmd.FindRecord Me!text_BuscarEst
  13.  
  14.     ID.SetFocus
  15.     studentRef = ID.Text
  16.     text_BuscarEst.SetFocus
  17.     search = text_BuscarEst.Text
  18.  
  19.     If studentRef = text_BuscarEst Then
  20.         MsgBox "Se encontró el #estudiante " & text_BuscarEst, vbOKOnly, "¡Felicidades!"
  21.         ID.SetFocus
  22.         txtSearch = ""
  23.       Else
  24.             MsgBox "Match Not Found For: " & text_BuscarEst & " - Please Try Again.", _
  25.             , "Invalid Search Criterion!"
  26.             text_BuscarEst.SetFocus
  27.  
  28.  
  29.     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.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#5: Jan 30 '07

re: Supress error message on FindRecord command


Try this version :
Expand|Select|Wrap|Line Numbers
  1. Dim studentRef As String
  2.     Dim search As String
  3. 'variables a usarse para guardarar los valores
  4. 'verifica si el campo text_barcode esta vacio
  5.     If IsNull(Me![text_BuscarEst]) Or (Me![text_BuscarEst]) = "" Then
  6.         MsgBox "¡Por favor ingrese un valor!", vbOKOnly, "Búsqueda inválida"
  7.         Me![text_BuscarEst].SetFocus
  8.     Exit Sub
  9. End If   
  10.     DoCmd.ShowAllRecords
  11.     DoCmd.GoToControl ("ID")
  12.     On Error Resume Next
  13.     DoCmd.FindRecord Me!text_BuscarEst
  14.     'You need to update this (following) line
  15.     If Err > 0 Then {failed}
  16.     On Error GoTo 0
  17.  
  18.     ID.SetFocus
  19.     studentRef = ID.Text
  20.     text_BuscarEst.SetFocus
  21.     search = text_BuscarEst.Text
  22.  
  23.     If studentRef = text_BuscarEst Then
  24.         MsgBox "Se encontró el #estudiante " & text_BuscarEst, vbOKOnly, "¡Felicidades!"
  25.         ID.SetFocus
  26.         txtSearch = ""
  27.       Else
  28.             MsgBox "Match Not Found For: " & text_BuscarEst & " - Please Try Again.", _
  29.             , "Invalid Search Criterion!"
  30.             text_BuscarEst.SetFocus
  31.  
  32.  
  33.     End If
Remember to update the line in bold.
Newbie
 
Join Date: Jan 2007
Posts: 4
#6: Feb 1 '07

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
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#7: Feb 1 '07

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.
Reply