By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,992 Members | 1,325 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,992 IT Pros & Developers. It's quick & easy.

DoCmd Apply filter

P: 73
I am trying to run a Apply filter for everytime someone opens Form_CC it will only show the Test (Test_ID) they are working on. This seems to be the closest I have gotten to filtering it correctly, however it doesn't work when the form is opened. Is there something I am doing wrong on this?

Private Sub Form_Open(Cancel As Integer)
DoCmd.ApplyFilter Form_CC.Form.filter = "Test_ID = 28"
Form_CC.Form.FilterOn = True

End Sub
Feb 20 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 446
Hi
Firstly, are you opening the form Form_CC from a control button on another form?
If you are you should use the Access Control Button Wizard. Make sure the magic wand icon is highlighted then click on the command button tool. After you draw your button the wizard will open then make the following selections.
'Form Operations' ==> 'Open Form' , specify the form to be opened (Form_CC) then name the button cmdOpenForm_CC. This will write the following code.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdOpenForm_CC_Click()
  3. On Error GoTo Err_cmdOpenForm_CC_Click
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.     stDocName = "frmChart"
  7.  
  8.     stLinkCriteria = "[Test_ID] =" & Me!ID    
  9.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  10.  
  11. Exit_cmdOpenForm_CC_Click:
  12.     Exit Sub
  13. Err_cmdOpenForm_CC_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_cmdOpenForm_CC_Click
  16.  
  17. End Sub
  18.  
I have added line 7 to define the criteria which assumes that the ID in question is a field on the current form.

If you are doing something more complicated you may need to create a Public variable (lngID) and set it so that the system 'knows' what Test_ID is being worked on and then use the DoCmd.OpenForm method described above.

I can't imagine when you would prefer the Filter technique but you could use it in the On_Current (or On_Open) event when it is simply
Expand|Select|Wrap|Line Numbers
  1.  Me.Filter = "Test_ID = " & lngID 
  2. Me.FilterOn = True
  3.  
I suppose opening the form with ALL records available then Filtering allows the filter to be changed (to view a different Test result) You would have to add an Unbound textbox, say called txtFilterTest_ID, then have an After_Update event ;
Expand|Select|Wrap|Line Numbers
  1.  Me.Filter = "Test_ID = " & Me!txtFilterTest_ID 
  2. Me.FilterOn = True
  3.  
Does this help?

S7
Feb 20 '08 #2

Expert Mod 2.5K+
P: 2,545
I am trying to run a Apply filter for everytime someone opens Form_CC it will only show the Test (Test_ID) they are working on. This seems to be the closest I have gotten to filtering it correctly, however it doesn't work when the form is opened. Is there something I am doing wrong on this?

Private Sub Form_Open(Cancel As Integer)
DoCmd.ApplyFilter Form_CC.Form.filter = "Test_ID = 28"
Form_CC.Form.FilterOn = True
End Sub
Hi. The DoCmd is not necessary:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Form_CC.Filter = "Test_ID = 28"
  3. Form_CC.FilterOn = True
  4.  
This will apply the filter whether or not you have a record with test_id = 28, however. Filters can also be removed by the user using the default menus (Records, Remove filter) unless you have disabled those menus.

-Stewart
Feb 20 '08 #3

P: 73
Hi. The DoCmd is not necessary:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Form_CC.Filter = "Test_ID = 28"
  3. Form_CC.FilterOn = True
  4.  
This will apply the filter whether or not you have a record with test_id = 28, however. Filters can also be removed by the user using the default menus (Records, Remove filter) unless you have disabled those menus.

-Stewart


Thanks I really appreciate it.....works Perfectly!!!!!
Feb 20 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.