Reference in Subform woes..

fenhow

Registered User.
Local time
Yesterday, 18:30
Joined
Jul 21, 2004
Messages
599
Hi, I have a search form that works great stand alone.
I want to add this form as a subform but when I do the code will not run.

Can someone tell me what I need to add to this code to make it run in a main form called frm_Main?

Thanks,
Fen

If Not IsNull(Me.txtStatus) Then
strStatus = "([Status] like ""*" & Me.txtStatus & "*"")"
strCriteria = strCriteria & " (" & strStatus & ")"
End If
 
You will need to change any reference that needs to refer to the main form so it refers to the main form. The code you posted would probably remain the same but the code that actually does the search will probably have to be changed. This web page will help to create references.

If you want further guidance I suggest you upload your database.
 
Thanks, so this is the full code that works in a stand alone form.
When I add this code to a main form as a sub-form I get no errors but it does not filter.
I looked at what you showed me but changing the reference to the controls does not seem to work. Any other suggestions.
Thanks

Option Compare Database

Public Sub cmdSearch_Click()
'FormName.Procedurename
Call Search
End Sub

Sub Search()
'Dim tempCriteriaForReport As TempVar
Dim strCriteria, strStatus, strYear, strMake, strModel As String
Dim varItem As Variant

'If Not IsNull (frm_Inventory!frm_Inventory_List!txtStatus)

'[frm_Inventory]![frm_Inventory_List]!

'''=========== code for status
'Forms![frm_Inventory]![frm_Inventory_List].Form![txtStatus]
'Me.[SubformName].Form.[ControlName]
'Forms!Orders![Orders Subform].Form.GetProductID



If Not IsNull(Me.txtStatus) Then
strStatus = "([Status] like ""*" & Me.txtStatus & "*"")"
strCriteria = strCriteria & " (" & strStatus & ")"
End If
'''=========== code for year
If Not IsNull(Me.txtYear) Then
strYear = "([Year] like ""*" & Me.txtYear & "*"")"
strCriteria = strCriteria & " And (" & strYear & ")"
End If
'''=========== code for make
If Not IsNull(Me.txtMake) Then
strMake = "([Make] like ""*" & Me.txtMake & "*"")"
strCriteria = strCriteria & " And (" & strMake & ")"
End If
'''=========== code for model
If Not IsNull(Me.txtModel) Then
strModel = "([Model] like ""*" & Me.txtModel & "*"")"
strCriteria = strCriteria & " And (" & strModel & ")"
End If
task = "select * from [qry_Inventory_List] where (" & strCriteria & ")"
Me.FilterOn = True

DoCmd.ApplyFilter task

'TempVars!tempCriteriaForReport = task '' set temp string criteria for report preview
'Me.txtTotal = FindRecordCount(task)
End Sub
 
I don't think you can use DoCmd.ApplyFilter in this situation. I suggest manipulating the filter on the main form directly something like.

Forms!MainFormName.Filter = strCriteria
Forms!MainFormName.FilterOn = True
 

Users who are viewing this thread

Back
Top Bottom