Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem opening form with filter 1

Status
Not open for further replies.

bmc1234

Programmer
Jul 21, 2005
50
US
I have a form with a button that, when pressed, opens another form with a filter based on the record from the first form. The problem is that the filter doesn't seem to be working. Instead of showing only certain records, it's showing all records. I have checked at various points to make sure the filter is there and have requeried at different points too, all to no avail. Basically, these are the lines in the onclick event to open the form:
Code:
Dim stLinkCriteria As String
    stLinkCriteria = "[repairdataID]=" & Me.[RepairID]
    stDocName = "ReplacedPart"
DoCmd.OpenForm stDocName, WhereCondition:=stLinkCriteria, DataMode:=acFormReadOnly
Here is the code for onactivate of the form being opened. I have used the code in the open and load events as well with no success.

Code:
Private Sub Form_Activate()

Debug.Print Me.RepairDataID & " - " & Me.RecordsetClone.RecordCount

'debug contents of recordset
    Debug.Print "***********"
    Do While Not Me.RecordsetClone.EOF
    Debug.Print Me.RecordsetClone.Fields(2)
    Me.RecordsetClone.MoveNext
    Loop
    
If Me.RecordsetClone.RecordCount < 1 Then
    'MsgBox "hi"
    Me.AllowAdditions = True
    Me.DataEntry = True
    'MsgBox "hi"
    'Me.RemovedPN.SetFocus
    Me.buttonnew.Visible = False
    Me.ButtonClose.Visible = True

    Debug.Print Me.RepairDataID & " - " & Me.RecordsetClone.RecordCount
    
'if there are items to display
Else
    'MsgBox "bad"
    Me.DataEntry = False
    Me.AllowAdditions = False
    Me.buttonnew.Visible = True
    Me.ButtonClose.Visible = False
End If
'Set rst = Nothing
'MsgBox Me.DataEntry
Debug.Print "----------"
End Sub

I have no idea why the filter isn't applying. If anybody knows that might be the answer to this problem, it would be greatly appreciated. Thanks.
 
How about...
Code:
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly


Randy
 
I've tried that too, it accomplishes the same thing.
 
That may have helped slightly. It doesn't work completely, but I noticed a pattern of some sort. Sometimes that msgbox will come up blank, meaning there's no filter at that time. Other times it'll display the proper filter. When it comes up blank it works, but when it displays the proper filter, it actually doesn't. That makes no sense to me and I can't figure out what's making it have the filter sometimes but not others. It seems completely erratic. Maybe that'll give somebody a clue to what's going on and how to fix it. Thanks for your help.
 
an update: it seems that it runs correctly (doesn't show filter is msgbox, but filters anyway) only the first time I run it after making changes to the code. If I comment out the msgbox line and run it, it'll be correct once. Then I uncomment the msgbox and it's right again, only once. Very weird.
 
Ok, I think I got it to work. I just took that me.filteron and moved it to the end of the onactivate method, after all the other code executes. Thanks to mp9 for leading me in the right direction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top