dbTalk Databases Forums  

Use TextBox on the main form to limit SubForm

comp.databases.ms-access comp.databases.ms-access


Discuss Use TextBox on the main form to limit SubForm in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dragon
 
Posts: n/a

Default Use TextBox on the main form to limit SubForm - 07-07-2010 , 01:40 AM






Hi,

I have a form with a text box and a subform. Main form is unbound. SubForm
is displaying records from a query. I would like to the user to be able to
enter text in the text box and subform to display records containing this
text with a field.

For Example:

SubForm Fields:
ID, [Full Name], City, PostCode

Date:
1, John Doe, London, as12as
2, John Tee, NY, 12345
3, Jane Doe, London, as12as

If user enters Doe into the text field, it should show records 1 and 3 in
the subform.

I have created an on-update event and tried to create a filter for the
subform but it does not seem to be working. The field I am trying to match
has a space in it ([Full Name]) and for some reason I can't seem to be able
to create an appropriate filter. Also, I want a 'Like' filter and not
'equal' filter.

Thank you for your help in advance.

Reply With Quote
  #2  
Old   
Jörn Bosse
 
Posts: n/a

Default Re: Use TextBox on the main form to limit SubForm - 07-07-2010 , 05:27 AM






Hello,

this might help you:

Dim strSQL As String
Dim strSearch As String
strSearch = Me.txtSearch.Text 'use your textfieldname instead
of txtSearch

strSQL = "SELECT * " & _
"FROM Yourtable " & _
"WHERE YourFieldinTable like '*" & strSearch & "*'"
Me.YourSubform.Form.RecordSource = strSQL

Reply With Quote
  #3  
Old   
Salad
 
Posts: n/a

Default Re: Use TextBox on the main form to limit SubForm - 07-07-2010 , 10:03 AM



Dragon wrote:
Quote:
Hi,

I have a form with a text box and a subform. Main form is unbound.
SubForm is displaying records from a query. I would like to the user to
be able to enter text in the text box and subform to display records
containing this text with a field.

For Example:

SubForm Fields:
ID, [Full Name], City, PostCode

Date:
1, John Doe, London, as12as
2, John Tee, NY, 12345
3, Jane Doe, London, as12as

If user enters Doe into the text field, it should show records 1 and 3
in the subform.

I have created an on-update event and tried to create a filter for the
subform but it does not seem to be working. The field I am trying to
match has a space in it ([Full Name]) and for some reason I can't seem
to be able to create an appropriate filter. Also, I want a 'Like' filter
and not 'equal' filter.

Thank you for your help in advance.

In the AfterUpdate event you can set a filter. Something like
If Not IsNull(Me.TextBoxName) then
strSearch = "FullName Like *" & Me.TextBoxName & "*"
Else
strSearch = "" 'will remove flter if blank
Endif

'set the filter
Forms!MainFormName!SubFormName.Form.Filter = strSearch
'turn the filter on or off
Forms!MainFormName!SubFormName.Form.FilterOn = (strSearch > "")

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.