Thelma Roslyn Lubkin wrote:
Quote:
I am still having trouble trying to use a popup form to allow user to
set filters for the main form.
The main form is based on a single table.
>
The popup contains 5 listboxes, so the user can filter on 5 fields in
this table, and can include as many field values as s/he needs.
The popup is reached from a command button on the main form
[I'm including only enough code to demonstrate what I'm trying to do]:
>
This button is on the main form, Datasystem:
Private Sub ButtonChooseFilter_Click()
>
Static intOpen As Integer
If intOpen = 0 Then
'Popup will remain open while main form is open
DoCmd.OpenForm "filterForDatasystem"
intOpen = 1
End If
'But popup will only be visible when user requests filter change
Forms!filterForDatasystem.Visible = True
Forms!filterForDatasystem.SetFocus
--------------------------
>
This button is on the popup, forFilterDatasystem
Sub ButtonApplyFilter_Click()
>
strSQL = SQLfilter 'Function SQLfilter builds SQL statement from the
'content of the listboxes
>
'Pass the filter, i.e. strSQL to a mainForm text box
Forms!Datasystem.txtSQL.Value = strSQL
Forms!Datasystem.SetFocus
>
'This instead of closing popup, as I want listboxes
'to retain their values for the next time user wants
'to change filter
Me.Visible = False
-----------------------------
>
'Back on the main form:
Private Sub Form_gotFocus()
>
Static strSQLText As String
>
If txtSQL.Value <strSQLText Then
>
Call Updatefilter
strSQLText = txtSQL.Value
End If
>
>
Sub Updatefilter()
>
strFilterSQL = txtSQL.Value
>
Me.Filter = strFilterSQL 'Set Filter criteria
Me.FilterOn = True 'Turn Filter on
'build txtFilters.value
Me.Requery 'Apply New Filter
>
I've been trying variations of this scheme for two days now
with no success.
>
At some point the whole process will lock up and I will get either
a polite Microsoft message that an unexplained error has occurred
and I've lost all my changes -- this is the gentlest blowup: at least
I can get to what I had before OR
>
The form cannot be opened because there isn't enough memory available.
This means I can't see it in design mode; I can't see its code: I have
nothing but my backup left [fortunately I have one]
>
I have no idea how to go about debugging such a thing: I tried to set
a breakpoint in the buttonApplyFilter_click routine and it was
ignored. I can't use debug.pring because my form is completely
unreachable after I try to run it...I need a debugging strategy
>
thanks, --thelma
>
When you set a filter, Me.Filter = "whatever", Me.FilterOn = True,
there's really no need to Requery...except to slow things down while
requerying your new filter that has just been applied.
Anyway, you use Forms!filterForDatasystem.SetFocus. I created 2 forms;
Form4 and Form5. Each form contains only a command button. You can
create them for testing if you'd like.
Form4's code
Private Sub Command0_Click()
If Not IsLoaded("Form5") Then 'see many examples for IsLoaded
DoCmd.OpenForm "Form5"
Else
Forms("Form5").Visible = True
DoCmd.SelectObject acForm, "Form5"
End If
End Sub
Private Sub Form_Activate()
MsgBox "Activate" 'always executes
End Sub
Private Sub Form_Close()
If IsLoaded("Form5") Then DoCmd.Close acForm, "Form5"
End Sub
Private Sub Form_GotFocus()
MsgBox "Form4 Got Focus" 'never executes
End Sub
Form5's code
Private Sub Command0_Click()
Me.Visible = False
Forms!Form4.Form.SetFocus 'kicks on Form4's Activate. Unneeded
MsgBox "Form5 SetFocus"
'You can comment out the above 2 lines and use the
'following instead of set focus.
DoCmd.SelectObject acForm, "Form4" 'kicks on Form4's Activate. Use
MsgBox "Form5 Select object"
End Sub
You mention that you posted only the necessary code. If you didn't get
the gist from the above code or from Lyle's code then that is where your
error is, not in the code you posted.