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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FilterByForm Disables Buttons on the Form

Status
Not open for further replies.

DeoM

Programmer
Jul 3, 2004
49
PH
Hi, I posted a similar question before but i got no right answers. Here's my problem. I made a form and a command button on it that activates "FilterByForm". I made another button on the form that activates "ApplyFilter". But when i actually click on the "FilterByForm" button, the "ApplyFilter" button is disabled; thus i cannot click it. Is there a way to make this button active programmatically?
 
Yes in the on_click event of the cmdFilterByForm make sure that the cmdApplyFilter.enabled = true.

You either have the command button disabled already or you are disabling it on the form_load event possibly.

 
Thanks for the response Ascentient.
But no, cmdApplyFilter is enabled; tried to enable it again on the on-click event of the cmdFilterByForm but it still disables automatically when i click cmdFilterByForm. Actually, all buttons and labels are automatically disabled whenever i click or activate FilterByForm. So when this happens, i have no other choice but use the ApplyFilter button on the Menu Bar. I would like to have an enabled cmdApplyFilter button on the form; you know; make it more user friendly to ordinary people. I would like to disable the Menu Bar to limit mistakes of users. Is there a way to have an enabled cmdApplyFilter button on the form?
 
I don't have a definitive answer for you but maybe what you could do is set up an on timer event that every 10-15 seconds prompt the user and ask if they want to remove the cmdfilterbyform option.

Is you form layed out in the datasheet style?
 
Well, I did a little more looking around and it looks like mave have to go the toolbar route. I found this example you could probably use to meet your needs.

I would copy and paste it to notepad, word, or your code editor to review it.

The routines here allow you to display a form in the Filter By Form mode. There are a number of steps required to ensure this example works.
In a module set a reference to the Microsoft Office 8 Object Library.
Create a toolbar called "Test Toolbar"
Add 2 buttons to the toolbar in the following order. (These must be the first 2 buttons on the toolbar for this to work as coded)
Name the first button "Filter By Form" and set the on action property to "=TBFilterForm()"
Name the second button "Close" and set the on action property to "=TBCloseFilter()"
Add the code headed Toolbar Code to a module
Add the code to the On Close and On Open events of the form
Change the Toolbar property of the form to "Test Toolbar"
'***************** Code Start *******************
' This code was originally written by Terry Wickenden.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.

'=========Toolbar Code=============
Function TBFilterForm()
Dim strTest As String
Dim ctl As CommandBarControl

Set ctl = CommandBars("Test Toolbar").Controls(1)
strTest = ctl.Caption
Select Case strTest
Case "Filter By Form"
DoCmd.RunCommand acCmdFilterByForm
'Remove any existing filter information
DoCmd.RunCommand acCmdClearGrid
ctl.Caption = "Apply Filter"
'Show the close button on the toolbar
CommandBars("Test Toolbar").Controls(2).Visible = True
Case "Apply Filter"
DoCmd.RunCommand acCmdApplyFilterSort
ctl.Caption = "Remove Filter"
'Hide the close button on the toolbar
CommandBars("Test Toolbar").Controls(2).Visible = False
Case "Remove Filter"
DoCmd.RunCommand acCmdRemoveFilterSort
ctl.Caption = "Filter By Form"
End Select

End Function

Function TBCloseFilter()
On Error GoTo ErrCloseFilter
'Reset the caption for the filter button
CommandBars("Test Toolbar").Controls(1).Caption = "Filter By Form"
'Hide the close button
CommandBars("Test Toolbar").Controls(2).Visible = False

DoCmd.RunCommand acCmdCloseWindow
Exit Function
ErrCloseFilter:

Select Case Err
Case 2501
' When you close the Filter Window
' Access thinks that you have canceled
' an action - do nothing
Case Else
MsgBox Err.Number & ":-" & vbCrLf & Err.Description
End Select

End Function
'====== End of Toolbar Code===========

'======== Form Code =============
Private Sub Form_Close()
'Make sure that the Tool bar has the correct caption
CommandBars("Test Toolbar").Controls(1).Caption = "Filter By Form"
'Display the close button on the toolbar - so it can be seen in design!!!
CommandBars("Test Toolbar").Controls(2).Visible = True

End Sub

Private Sub Form_Open(Cancel As Integer)
'Hide the close button on the toolbar
CommandBars("Test Toolbar").Controls(2).Visible = False

End Sub
'====== End of Form Code ================

'****************** Code End ********************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top