docmd.findrecord is being a beast (1 Viewer)

John Sh

Member
Local time
Tomorrow, 00:32
Joined
Feb 8, 2021
Messages
408
I know there have been numerous threads on this subject but none of them are giving me the right answer.
The format appears to be quite straight forward but I have tried everything and can't make it go.
I even have a problem in that just putting in comma's for the optional parameters causes the system to insist on named parameters.
This is what I have. I have tried the search string with and without quotes. I am getting the error message below, which really doesn't help very much.
If I run debug it throws no errors.
Code:
Private Sub CboName_AfterUpdate()
    Dim strFinder As Variant
    strFinder = Me.cboName.Value
    Me.txtMsg.Visible = False
    DoCmd.FindRecord "strFinder", match:=anywhere, matchcase:=False, search:=acSearchAll, OnlyCurrentField:=acAll
    strFinder = [walls]![Name]
    If IsNull(rs!Photo) Then
        Me.BtnPhoto.ForeColor = RGB(100, 100, 100)
    Else
        Me.BtnPhoto.ForeColor = RGB(255, 255, 255)
    End If
    Me.cboName = ""
End Sub
Screenshot_12.jpg
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:32
Joined
May 7, 2009
Messages
19,230
you need to Setfocus on any find first:

Me.textbox.Setfocus
DoCmd.FindRecord ...
 

John Sh

Member
Local time
Tomorrow, 00:32
Joined
Feb 8, 2021
Messages
408
you need to Setfocus on any find first:

Me.textbox.Setfocus
DoCmd.FindRecord ...
Tried that, gets the same error message.
Setfocus on the calling combobox and on the first text box the result will go to.
Actually most of the fields in the resulting record will populate bound text boxes
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:32
Joined
May 7, 2009
Messages
19,230
see this demo.
 

Attachments

  • dbGotoRecord.accdb
    540 KB · Views: 358

John Sh

Member
Local time
Tomorrow, 00:32
Joined
Feb 8, 2021
Messages
408
This has got to the ridiculous stage.
I have copied your line of code and inserted my combobox name.
I am getting the same error.
My combobox is supplied via a query which draws it's information from a field in a table.
All simple and basic. So far the only thing that finds the record is to use a recordset but that has it's own set of problems when it comes to updating many controls.
I can only assume there is some error tucked away somewhere that is causing this as everything I have done sofar should have worked.
John
 

John Sh

Member
Local time
Tomorrow, 00:32
Joined
Feb 8, 2021
Messages
408
see this demo.
I knew it was something stupid. I had the control source of the combobox set to a field. Removed that and it's all good.
Thank you for your assistance.
.John
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 15:32
Joined
Sep 12, 2006
Messages
15,651
I can see it's sorted, but I added a couple of other thoughts.

1 DoCmd.FindRecord "strFinder", match:=anywhere, matchcase:=False, search:=acSearchAll, OnlyCurrentField:=acAll
2 strFinder = [walls]![Name]

line 2 needs to be before line 1
in line 1, the red bit needs to be the variable name, rather than the string. I imagine that's how you fixed it.

There is also a "findfirst" argument. I tend to have two buttons - one for findfirst, and one for findnext - so a FindFirst:=true finds the first match, and FindFirst:=false finds the next (and successive) matches, when the search criteria is acAnywhere (ie just part of the field, rather than the whole field)

In passing, I also use OnlyCurrentField:=acCurrent as I always know which column I am searching.

I imagine it's possible for your version to locate the wrong row because of the search criteria you are actually using.
 

John Sh

Member
Local time
Tomorrow, 00:32
Joined
Feb 8, 2021
Messages
408
Thanks Gemma.
The problem was with the combobox being bound to the field I was searching. If you look at my code above you will see that the code in your line 2 was an attempt to see if the findrecord had done anything. strfinder was initialised and then had the combobox stored in it before the findrecord line.
 

Users who are viewing this thread

Top Bottom