How to Rid Go To Code of a Filter

D

doyle60

The code below is placed on the Got Focus property of a form with a
datasheet sub. If the underlying form is open, it will go to the
record that has the focus of the popup datasheet. It works. But the
problem is that it filters the underlying form. I don't want it to
filter. I have a method for taking this filter off, but it isn't
working here. I get a data mismatch error. But the data is a match,
coming from the same table.

Can anyone suggest how to take the filter off, preferably something
added to the code at the bottom, to avoid this data mismatch.

Thanks,
_______________________

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
_______________________

Matt
 
D

Dirk Goldgar

The code below is placed on the Got Focus property of a form with a
datasheet sub. If the underlying form is open, it will go to the
record that has the focus of the popup datasheet. It works. But the
problem is that it filters the underlying form. I don't want it to
filter. I have a method for taking this filter off, but it isn't
working here. I get a data mismatch error. But the data is a match,
coming from the same table.

Can anyone suggest how to take the filter off, preferably something
added to the code at the bottom, to avoid this data mismatch.

Thanks,
_______________________

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
_______________________

Matt

I'm not entirely sure I understand your setup, or exactly what you want
to achieve. But if you just want to position the form
"ChargeBackHeaderfrm" to the CBID that is current on the form where the
code runs -- without actually filtering the form to just that record --
then you might modify it like this:

'----- start of suggested code -----
Private Sub Command49_Click()

On Error GoTo Err_Command49_Click

Dim stDocName As String
Dim frm As Access.Form

stDocName = "ChargeBackHeaderfrm"

If IsOpen(stDocName) Then

Set frm = Forms(stDocName)

With frm.RecordsetClone
.FindFirst "[CBID]=" & Me![CBID]
If Not .NoMatch Then
frm.Bookmark = .Bookmark
End If
End With

Set frm = Nothing

End If

Exit_Command49_Click:
Exit Sub

Err_Command49_Click:
MsgBox Err.Description
Resume Exit_Command49_Click
End If

'----- end of suggested code -----
 
D

doyle60

Thanks,
I got it to work. In my code, for some forms, I have to use the line:

stLinkCriteria="[CBID]=" & "'" & Me![CBID] & "'"

But I see in some forms I have to augment that line to this:

stLinkCriteria="[CBID]=" & Me![CBID]

I don't quite understand why. But all works now.

Thanks,

Matt
 
D

Dirk Goldgar

Thanks,
I got it to work. In my code, for some forms, I have to use the line:

stLinkCriteria="[CBID]=" & "'" & Me![CBID] & "'"

But I see in some forms I have to augment that line to this:

stLinkCriteria="[CBID]=" & Me![CBID]

I don't quite understand why. But all works now.

That's odd, because it implies that CBID is a text field in some places,
and a numeric field in others. I'd expect the same logical field to
have the same data type wherever it appears.
 

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