FindRecord Error

D

Dinsdale

Hi guys,

Getting very annoyed with this one. I have previously successfully used code
behind a Close button on a single record form to take me back to the
appropriate record on a list. Code used the FindRecord command to link
between the two forms e.g.

Forms![Employee List].Requery
DoCmd.OpenForm ("Employee List")
Forms![Employee List]![EmployeeID].Visible = True
DoCmd.GoToControl "EmployeeID"
DoCmd.FindRecord Forms![Employee Details]![EmployeeID], acEntire, ,
, , acCurrent
DoCmd.GoToControl "Employee Name"
Forms![Employee List]![EmployeeID].Visible = False

This code works well. So I transferred and modified the code to work in
another database - or so I thought. Here's the modified code:

Forms![CAN6].Requery
DoCmd.OpenForm ("CAN6")
Forms![CAN6]![CANDIDATEID].Visible = True
Forms![CAN6]![CANDIDATEID].SetFocus
DoCmd.FindRecord Forms![CAN2 INPUT]![CANDIDATEID], acEntire, , , ,
acCurrent
Forms![CAN6]!cmdClose.SetFocus
Forms![CAN6]![CANDIDATEID].Visible = False

This code generates the 2162 error - 'A macro set to one of the current
field properties failed because of an error in a FindRecord action argument'.
I have compared field properties until I'm going blind. Any ideas why the
latter code won't work?

TIA

Andrew
 
W

Wayne Morgan

Is the form [CAN2 INPUT] open when you run this? If so, then I would look
for a spelling error in the name of the form or control. Double check that
the actual names of the report and control are what you have typed. Also,
check to see if the data type of the control is the same as the data type of
the control on the form you are searching.
 
D

Dinsdale

Thanks Wayne,

Yes, CAN2 INPUT is open, and I've checked for spelling errors. The data type
should be same, but I will check on that.

thanks

Andrew

Wayne Morgan said:
Is the form [CAN2 INPUT] open when you run this? If so, then I would look
for a spelling error in the name of the form or control. Double check that
the actual names of the report and control are what you have typed. Also,
check to see if the data type of the control is the same as the data type of
the control on the form you are searching.

--
Wayne Morgan
MS Access MVP


Dinsdale said:
Hi guys,

Getting very annoyed with this one. I have previously successfully used
code
behind a Close button on a single record form to take me back to the
appropriate record on a list. Code used the FindRecord command to link
between the two forms e.g.

Forms![Employee List].Requery
DoCmd.OpenForm ("Employee List")
Forms![Employee List]![EmployeeID].Visible = True
DoCmd.GoToControl "EmployeeID"
DoCmd.FindRecord Forms![Employee Details]![EmployeeID], acEntire, ,
, , acCurrent
DoCmd.GoToControl "Employee Name"
Forms![Employee List]![EmployeeID].Visible = False

This code works well. So I transferred and modified the code to work in
another database - or so I thought. Here's the modified code:

Forms![CAN6].Requery
DoCmd.OpenForm ("CAN6")
Forms![CAN6]![CANDIDATEID].Visible = True
Forms![CAN6]![CANDIDATEID].SetFocus
DoCmd.FindRecord Forms![CAN2 INPUT]![CANDIDATEID], acEntire, , , ,
acCurrent
Forms![CAN6]!cmdClose.SetFocus
Forms![CAN6]![CANDIDATEID].Visible = False

This code generates the 2162 error - 'A macro set to one of the current
field properties failed because of an error in a FindRecord action
argument'.
I have compared field properties until I'm going blind. Any ideas why the
latter code won't work?

TIA

Andrew
 
D

Dinsdale

Hi Wayne,

The only difference that I can see is that one form is based on a table, and
the other on a query. Potentially the issue?

Andrew

Wayne Morgan said:
Is the form [CAN2 INPUT] open when you run this? If so, then I would look
for a spelling error in the name of the form or control. Double check that
the actual names of the report and control are what you have typed. Also,
check to see if the data type of the control is the same as the data type of
the control on the form you are searching.

--
Wayne Morgan
MS Access MVP


Dinsdale said:
Hi guys,

Getting very annoyed with this one. I have previously successfully used
code
behind a Close button on a single record form to take me back to the
appropriate record on a list. Code used the FindRecord command to link
between the two forms e.g.

Forms![Employee List].Requery
DoCmd.OpenForm ("Employee List")
Forms![Employee List]![EmployeeID].Visible = True
DoCmd.GoToControl "EmployeeID"
DoCmd.FindRecord Forms![Employee Details]![EmployeeID], acEntire, ,
, , acCurrent
DoCmd.GoToControl "Employee Name"
Forms![Employee List]![EmployeeID].Visible = False

This code works well. So I transferred and modified the code to work in
another database - or so I thought. Here's the modified code:

Forms![CAN6].Requery
DoCmd.OpenForm ("CAN6")
Forms![CAN6]![CANDIDATEID].Visible = True
Forms![CAN6]![CANDIDATEID].SetFocus
DoCmd.FindRecord Forms![CAN2 INPUT]![CANDIDATEID], acEntire, , , ,
acCurrent
Forms![CAN6]!cmdClose.SetFocus
Forms![CAN6]![CANDIDATEID].Visible = False

This code generates the 2162 error - 'A macro set to one of the current
field properties failed because of an error in a FindRecord action
argument'.
I have compared field properties until I'm going blind. Any ideas why the
latter code won't work?

TIA

Andrew
 
W

Wayne Morgan

In that case, I would start suspecting some focus problems. DoCmd works on
the object with the focus, which is why you're moving the focus. It may be
easier to use the DAO FindFirst command on the form's Recordset. This will
require setting a Reference for DAO if you haven't already.

Forms!Can6.Recordset.FindFirst "CandidateID=" & Forms![Can2
Input]!CandidateID

This will save all of the visible/not visible, set focus lines. The syntax
above assumes CandidateID to be a number field, if it is defined as a text
field (even if it contains a number) then the syntax would be:

Forms!Can6.Recordset.FindFirst "CandidateID='" & Forms![Can2
Input]!CandidateID & "'"
 
D

Dinsdale

Hi Wayne,

Mmm. Recordset isn't going to work because the source form for the match is
using a recordset to set up conditions for navigation buttons and gives rise
to a conflict. Pity because it was a more elegant solution:)

Regards

Andrew

Wayne Morgan said:
In that case, I would start suspecting some focus problems. DoCmd works on
the object with the focus, which is why you're moving the focus. It may be
easier to use the DAO FindFirst command on the form's Recordset. This will
require setting a Reference for DAO if you haven't already.

Forms!Can6.Recordset.FindFirst "CandidateID=" & Forms![Can2
Input]!CandidateID

This will save all of the visible/not visible, set focus lines. The syntax
above assumes CandidateID to be a number field, if it is defined as a text
field (even if it contains a number) then the syntax would be:

Forms!Can6.Recordset.FindFirst "CandidateID='" & Forms![Can2
Input]!CandidateID & "'"

--
Wayne Morgan
MS Access MVP


Dinsdale said:
Hi Wayne,

The only difference that I can see is that one form is based on a table,
and
the other on a query. Potentially the issue?
 
W

Wayne Morgan

Then I would suspect that this conflict is why the DoCmd.GoToRecord isn't
working.
 
D

Dinsdale

Wayne said:
Then I would suspect that this conflict is why the DoCmd.GoToRecord isn't
working.
Hi Wayne,

No - the same recordset code is working under the forms in the database
that is working. I still suspecting the difference is based on the
problem set being based on a query while the working set based on a
table. Thanks anyway.

Andrew
 

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