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

Referencing a subform

Status
Not open for further replies.

serino

Programmer
Feb 13, 2003
107
US
I am having some trouble referencing a subform using the string below...

If Not IsNull(Me.[txtFilteraccountrep]) Then

strWhere = strWhere & "(Forms.F_012_Won_Loss_Form.Form.[AccountRep] Like ""*" & Me.txtFilteraccountrep & "*"") AND "

End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then

MsgBox "No criteria", vbInformation, "Search Criteria Not Found."
Else
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
End If

Thank you for your assistance.
 
Even if you fix the subform reference, this will not work. No idea what you are trying, but it makes no sense.

As far as the reference. Forms is a collection or the open forms. A collection has items in it. An item is not a property. However controls on a form are both properties and items in a collection (which is pretty confusing). So you can either do
Forms!FormName.SubFormControlName.Form with bang notation for an item in a collection
or
Forms("FormName").SubFormControlName.Form with dot notation for an item in a collection
But not
Forms.FormName.SubFormControlName.Form
If the code is called from the current form then simply
Me.SubformControl.Form

As I said controls are both items in a collection and properties so you can do either

Forms("FormName").SubFormControlName.Form
or
Forms("FormName")!SubFormControlName.Form

 
Wow...I should have proof read my question.

I have a command button in my subform which filters the records within. I would like to take that filter out of the subform and place it onto the mainform and still have it work the same way filtering records in the subform. How do I accomplish this?


Dim strWhere As String

Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"

If Not IsNull(Me.txtFilteraccountrep) Then
strWhere = strWhere & "([AccountRep] Like ""*" & Me.txtFilteraccountrep & "*"") AND "
End If

If Not IsNull(Me.txtFilterStatus) Then
strWhere = strWhere & "([Status] Like ""*" & Me.txtFilterStatus & "*"") AND "
End If

If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & "([ClosedDate] >= " & Format(Me.txtStartDate, conJetDate) & ") AND "
End If

If Not IsNull(Me.txtEndDate) Then 'Less than the next day.
strWhere = strWhere & "([ClosedDate] < " & Format(Me.txtEndDate + 1, conJetDate) & ") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then

MsgBox "No criteria", vbInformation, "Search Criteria Not Found."
Else

strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True

End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top