How to Correct Go To Certain Record Code without Filtering

D

doyle60

I have an unbound subform on a main form that I want to use to direct
the main form to a certain record. When a certain field in the subform
has the focus, I want the main form to move to that record. The trick
is I also do not want it to filter the form in any way. (The subform
contains three fields, the key, and two fields used to filter it.)

Access writes the following code when placing a command button down to
go to a certain record:
____________

If IsOpen("ChargeBackHeaderfrm") Then

On Error GoTo Err_Command49_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "ChargeBackHeaderfrm"

stLinkCriteria = "[CBID]=" & Me![CBID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command49_Click:
Exit Sub

Err_Command49_Click:
MsgBox Err.Description
Resume Exit_Command49_Click
End If
_________________

I placed the above in the got focus property of the Key control in the
subform. This wonderous code, however, filters the form. If the user
presses the filter off, the form hops to the first record. So I
usually edit the above code to the following:
_________________

If IsOpen("ChargeBackHeaderfrm") Then

On Error GoTo Err_Command49_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim rsFind As Recordset

stDocName = "ChargeBackHeaderfrm"

stLinkCriteria = "[CBID]=" & Me![CBID]
DoCmd.OpenForm stDocName
Set rsFind = Forms(stDocName).RecordsetClone
rsFind.FindFirst stLinkCriteria
Forms(stDocName).Bookmark = rsFind.Bookmark

Exit_Command49_Click:
Exit Sub

Err_Command49_Click:
MsgBox Err.Description
Resume Exit_Command49_Click
End If
_________________

But this isn't working for me now. It got an error on the line:

rsFind.FindFirst stLinkCriteria

But I can't now recreate that. It now says "Data type mismatch in
criteria expression."

The CBID, however, are both autonumber fields, coming from the same
table.

How do I alter the code, or what may be wrong?

Thanks,

Matt
 

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