Share via

DoCmd.SearchForRecord doesn't work

Anonymous
2017-06-06T22:15:12+00:00

I run into many times that this command does not work.

In this case

DoCmd.SearchForRecord , "", acFirst, "[UsrTypID] = " & Nz(Screen.ActiveControl, 0)

does not find the record, then when trying to leave the form I will get an error message that it is trying to write a duplicate record

The form is bound to the correct table, the primary key for the table is UsrTypID and the active control has the correct value.  UsrTypID is an integer.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2017-06-07T01:34:23+00:00

Hmm, okay then try this...

Me.Recordset.FindFirst "UsrTypID= " & NameOfYourControlHere

...let me know what happens

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2017-06-07T12:49:15+00:00

    That worked.  Thanks

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2017-06-07T01:09:26+00:00

    It is on an unbound control.  I have this happen quite often.  This time it is in 2016 but I have had this occur in 2003, 2007, 2010 and 2013 as well.  Usually I have to either treat the form as unbound or unbind the form.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2017-06-06T23:57:42+00:00

    Sounds like you are using it on a BOUND control?  That line should be used on an UNBOUND control as it is looking for the record.

    Was this answer helpful?

    0 comments No comments