filter subform

J

Jologs

Hi:

I want to filter my subform (bound to table) when it loads. I've tried the
codes below but it returns "You cancelled the previous operation"

Private Sub Form_Load()
Me.FilterOn = True
Me.Filter = "[Status]='False'"
End Sub

[Status] is a checkbox.

Actually, before the main form loads I click a button from another form with
the following criteria (for the Main Form)

stLinkCriteria = "[Assignor]=" & "'" & Me![txtUserID] & "'"

I have tried adding the criteria for the subform but it prompts a screen
asking for the value for the subform

stLinkCriteria = "[Assignor]=""" & Me![txtUserID] & """ AND
Me![frmAssignment].Form![optStatus]= False")

Thanks in advance
 
A

Allen Browne

If Status is a Yes/No field, it can contain the value True or False. It
cannot contain the *text* 'True' or the text 'False'. (Note the quotes,
indicating text.)

Try:
Private Sub Form_Load()
Me.Filter = "[Status] = False"
Me.FilterOn = True
End Sub

If you do not need the user to be able to easily load the records where
Status is True, it would probably be better to create a query that selects
only the desired records, and set the form's RecordSource to that query.
 
J

Jologs

Huh, that was so easy. Many thanks.
--
Allan - http://allanmagtibay.hostrocket.com


Allen Browne said:
If Status is a Yes/No field, it can contain the value True or False. It
cannot contain the *text* 'True' or the text 'False'. (Note the quotes,
indicating text.)

Try:
Private Sub Form_Load()
Me.Filter = "[Status] = False"
Me.FilterOn = True
End Sub

If you do not need the user to be able to easily load the records where
Status is True, it would probably be better to create a query that selects
only the desired records, and set the form's RecordSource to that query.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Jologs said:
Hi:

I want to filter my subform (bound to table) when it loads. I've tried the
codes below but it returns "You cancelled the previous operation"

Private Sub Form_Load()
Me.FilterOn = True
Me.Filter = "[Status]='False'"
End Sub

[Status] is a checkbox.

Actually, before the main form loads I click a button from another form
with
the following criteria (for the Main Form)

stLinkCriteria = "[Assignor]=" & "'" & Me![txtUserID] & "'"

I have tried adding the criteria for the subform but it prompts a screen
asking for the value for the subform

stLinkCriteria = "[Assignor]=""" & Me![txtUserID] & """ AND
Me![frmAssignment].Form![optStatus]= False")

Thanks in advance
 
Top