findrecord in Access 2000

P

pvp

Guys,

at the end of a button on a form opened on a table, I
have the following code:

"
On Error GoTo Err_Command3_Click

DoCmd.FindRecord "cccc", acAnywhere, False,
acSearchAll, False, acAll, True

Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
"

This produces this error:

"
a macro set to one of the current field's properties has
failed because of an error in a findmacro action argument
"

I am pretty damn sure the arguments are correct so what
gives?????

Overflowing gratitude for any hints, preferably useful
ones...
 
A

Andy Cole

Hello pvp

When you click on the button you have moved the focus off the current
record's control and so the Find Record has nothing to search as no data is
bound to the button. To fix the problem, set the focus back to a control
bound to a recordset field. If you can guarantee that the previous control
could only be a bound control then use;

Screen.PreviousControl.SetFocus
DoCmd.FindRecord.....

otherwise somthing like;

Me.firstcontrol.SetFocus
DoCmd.FindRecord....

HTH

Andy
 
P

pvp

Andy,

Your answer solved the immediate problem but now I am up
to another.

I have in my form associated with a table a button ('find
first') with this code behind it:

"
Private Sub Command80_Click()
On Error GoTo Err_Command3_Click

Forms![counselling Log]!
date_on_form.SetFocus 'asociate with underlying table
DoCmd.FindRecord Me.Text81, acAnywhere, False,
acSearchAll, False, acAll, True

Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub
"

and another ('find next') with this code behind it:

"
Private Sub Command84_Click()
On Error GoTo Err_Command84_Click


Me.Text81.SetFocus
Me.Text81 = ""
DoCmd.FindNext

Exit_Command84_Click:
Exit Sub

Err_Command84_Click:
MsgBox Err.Description
Resume Exit_Command84_Click

End Sub
"

I put a string to look for in the control 'text81'.
I hit the first button and it merely goes to the first
record in the table, whatever is in text81.
Then I hit the second button repeatedly and the table in
the form moves to the first, then second, etc... records
that contain the string I put in text81. Btw, the second
button only works this well when I delete the contents of
text81 before employing it. Hence the 'Me.Text81 = ""
' line in the second button's code.

In the words of Shakespeare, 'it is a mystery' which I
would value someone resolving...

Any clues?

Same unbounded gratitude...
 
A

Andy Cole

Hi pvp

If you don't clear the 'Find What' textbox. Text81 what will happen is that
the .FindNext finds what's in the 'Find What'. I would suggest one of the
following;

1.
Change the 'Find' button code to;

Private Sub Command80_Click()
On Error GoTo Err_Command3_Click

Dim varFW As Variant

' As you are dealing with 1 form only, The following line;
' Forms![counselling Log]!date_on_form.SetFocus 'asociate with
underlying table
' could be replaced with this;
Me.date_on_form.SetFocus
varFW = Me.Text81
Me.Text81 = Null
DoCmd.FindRecord varFW, acAnywhere, False, acSearchAll, False, acAll,
True

Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub

and the 'Find Next' to;

Private Sub Command84_Click()
On Error GoTo Err_Command84_Click

Me.Text81.SetFocus
DoCmd.FindNext

Exit_Command84_Click:
Exit Sub

Err_Command84_Click:
MsgBox Err.Description
Resume Exit_Command84_Click

End Sub


2.
This is the code that I use in my apps.
Use the built-in Find/Replace option using the following code on the 'Find'
button ( remove the Find Next button) abd the 'Find What' textbox (Text81)

Private Sub Command80_Click()
On Error GoTo Err_Command3_Click


' See notes about next line
' Me.AllowEdits = False

Me.date_on_form.SetFocus

' The next line initialises the settings for the Find/Replace
' dialog but as the last parameter is False, does not start the search

DoCmd.FindRecord " ", acAnywhere, , , True, acAll, False

' The next line opens the Find/Replace dialog. When first
' called, the "Find What" will be blank.

RunCommand acCmdFind


' See notes about next line
' Me.AllowEdits = True

Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub

Notes:
The advantage of calling the Find/Replace is mainly as you'll get a message
when there are no more records that match the 'Find What'. If you do not
want the Replace functionality, un-rem the Form's AllowEdits lines in the
above.

HTH

Andy

pvp said:
Andy,

Your answer solved the immediate problem but now I am up
to another.

I have in my form associated with a table a button ('find
first') with this code behind it:

"
Private Sub Command80_Click()
On Error GoTo Err_Command3_Click

Forms![counselling Log]!
date_on_form.SetFocus 'asociate with underlying table
DoCmd.FindRecord Me.Text81, acAnywhere, False,
acSearchAll, False, acAll, True

Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub
"

and another ('find next') with this code behind it:

"
Private Sub Command84_Click()
On Error GoTo Err_Command84_Click


Me.Text81.SetFocus
Me.Text81 = ""
DoCmd.FindNext

Exit_Command84_Click:
Exit Sub

Err_Command84_Click:
MsgBox Err.Description
Resume Exit_Command84_Click

End Sub
"

I put a string to look for in the control 'text81'.
I hit the first button and it merely goes to the first
record in the table, whatever is in text81.
Then I hit the second button repeatedly and the table in
the form moves to the first, then second, etc... records
that contain the string I put in text81. Btw, the second
button only works this well when I delete the contents of
text81 before employing it. Hence the 'Me.Text81 = ""
' line in the second button's code.

In the words of Shakespeare, 'it is a mystery' which I
would value someone resolving...

Any clues?

Same unbounded gratitude...
-----Original Message-----
Hello pvp

When you click on the button you have moved the focus off the current
record's control and so the Find Record has nothing to search as no data is
bound to the button. To fix the problem, set the focus back to a control
bound to a recordset field. If you can guarantee that the previous control
could only be a bound control then use;

Screen.PreviousControl.SetFocus
DoCmd.FindRecord.....

otherwise somthing like;

Me.firstcontrol.SetFocus
DoCmd.FindRecord....

HTH

Andy




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top