form and subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a question on main form and Subform. is it necessary that the main
form and the subform shoule be linked. Like having two tables link to each
other. cause i have a form with few option group on it that i am using to
filter data. I have code behide the Apply filter command button. but its not
working to filter on the subform. I got it to work so it filters using
reports. but i want the data to show on the subform. Do i have to have the
Main form and the Subform link though two different tables?
 
When you hit your apply filter button you probably need to requery the
subform, Me.SubformName.Requery I don't know exactly what you are
trying to do, so I don't know if this will resolve your issue with
certainty or not.

In answer to your question though, no you don't have to link a form and
subform.
 
When you hit your apply filter button you probably need to requery the
subform, Me.SubformName.Requery I don't know exactly what you are
trying to do, so I don't know if this will resolve your issue with
certainty or not.

In answer to your question though, no you don't have to link a form and
subform.


Actually, can a subform form be linked to a form based on a like statement
type of thing?

If I have a table say, all different books, and another table that describes
different subject matter.

I could have a main form that shows the subject matter table, one record at a
time. So, on the main form, I pick the subject "Home", could I have my Book
title subform show me all the records with a name like "*home*" in it, so
that I get titles, home repair, home improvement, looks for your home etc.?
 
this is the code i have behide Apply filter i have 4 option group and one
combo box. at the end do i just add the code you told me so it will be
requery to the subform. I have a table really its a query that is link to
the subform that shows all the fields from the main table. do i have to
have a totally different code to filter on a subform instead of the report?



Dim strAdtype As String
Dim strbookname As String
Dim stradvertiser As String
Dim strheading As String
Dim strudac As String
Dim strfilter As String

Select Case Me.fraAdType.Value
Case 1
strAdtype = "='Comp'"
Case 2
strAdtype = "='YB'"
Case 3
strAdtype = "='Canceled'"
Case 4
strAdtype = "like '*'"
End Select





If IsNull(Me.txtbookname.Value) Then
strbookname = "Like '*'"
Else
Select Case Me.fraBookName.Value
Case 1
strbookname = "Like '" & Me.txtbookname.Value & "*'"
Case 2
strbookname = "Like '*" & Me.txtbookname.Value & "*'"
Case 3
strbookname = "Like '*" & Me.txtbookname.Value & "'"
Case 4
strbookname = "= '" & Me.txtbookname.Value & "'"
End Select
End If



If IsNull(Me.txtAdvertiser.Value) Then
stradvertiser = "Like '*'"
Else
Select Case Me.fraAdvertiser.Value
Case 1
stradvertiser = "Like '" & Me.txtAdvertiser.Value & "*'"
Case 2
stradvertiser = "Like '*" & Me.txtAdvertiser.Value & "*'"
Case 3
stradvertiser = "Like '*" & Me.txtAdvertiser.Value & "'"
Case 4
stradvertiser = "= '" & Me.txtAdvertiser.Value & "'"
End Select
End If



If IsNull(Me.TxtHeading.Value) Then
strheading = "Like '*'"
Else
Select Case Me.FraHeading.Value
Case 1
strheading = "like '" & Me.TxtHeading.Value & "*'"
Case 2
strheading = "Like '*" & Me.TxtHeading.Value & "*'"
Case 3
strheading = "Like '*" & Me.TxtHeading.Value & "'"
Case 4
strheading = Me.TxtHeading.Value & ""
End Select
End If


If IsNull(Me.CboUDAC.Value) Then
strudac = "like '*'"
Else
strudac = "='" & Me.CboUDAC.Value & "'"
End If

strfilter = "[type] " & strAdtype & " and [bookname] " & strbookname & "
and [advertiser] " & stradvertiser & " and
" & strheading & " and
[udac_code]" & strudac

With Reports![rptmeterad]
.filter = strfilter
.FilterOn = True

End With​
 
Yes, that is certainly a possibility. You can do it one of two way
that I can think of.

1. Your subform's recordset would need to be based on a query of your
titles. In the criteria of the title field you would need to put
Like "*" & Forms!MainFormName!SubjectFieldName & "*"
In your AfterUpdate property of your Subject Field, put
Me.SubformName.Requery
You need to replace MainFormName, SubjectFieldName and SubformName with
the actual names you called them.

OR

2. Again in the after update property of your subject field, put
Me.SubformName.Form.Filter = "BookTitle Like '*'" & Me.SubjectFieldName
& "'*'"
Me.SubformName.Requery

Hope that helps you!
 
Yes to filter the subform you want:
Me.SubformName.Form.Filter = strfilter
Me.SubformName.Form.FilterOn = True
 
Back
Top