** HELP***Filtering Subform by textbox AND combobox values!!!

emilyanne2010

New member
Local time
Today, 06:08
Joined
Feb 2, 2011
Messages
1
I am relatively new to access and I am creating a database for work.
The main use for this database will be through the main form- it has a subform in it which is linked to the table "Opportunities".

I basically want to have at the top of this form 3 comboboxes, 2 textboxes, one checkbox and maybe 2 dateboxes.
I would like the user to be able to enter values in some/all of the fields and then click a button and the subform finds any matching records. I can manage to get the text boxes to filter using an after update code that filter but they do not work together and they can contradict each other.

So please if any kind soul could have a think about my problem and give me any help it would be much appreciated. i have been working on it for days now and don't seem to be making any progress

The subform is called - "Opportunity Details"
Thank you Soooooo much!!
Emily

EDIT_
this is the code I am trying to recycle from another database- please help if you have ANY idea what is going wrong. I am trying to filter by using this code but when i click apply filter nothing happens not even any errors!!


Private Sub Cmd_apply_Click()
Dim strSQL As String
Dim strWhere As String
Dim qdf As QueryDef
strSQL = csfixedSQL



If ((Chk_log_name) And Not (IsNull(Cmb_name.Value))) Then
strWhere = " AND [Opportunities].[Location Country] = """ & Cmb_name.Value & """"
End If
If ((Check196) And Not (IsNull(Combo198.Value))) Then
strWhere = " AND [Opportunities].[Sales Responsibility] = """ & Combo198.Value & """"
End If


If ((Check199) And Not (IsNull(Check202.Value))) Then
strWhere = " AND [Opportunities].[Customer has order to place] = """ & Check202.Value & """"
End If


If ((Chk_log_id) And Not (IsNull(Cmb_TLA.Value))) Then
strWhere = strWhere & " AND [Opportunities].[Customer] = """ & Cmb_TLA.Value & """"
End If
If ((Chk_log_sap) And Not (IsNull(Txt_log_sap.Value))) Then
strWhere = strWhere & " AND [Opportunities].[Location City] Like """ & "*" & Txt_log_sap.Value & "*"""
End If
If ((Chk_log_job) And Not (IsNull(Txt_log_job.Value))) Then
strWhere = strWhere & " AND [Opportunities].[Opportunities.ID] Like """ & "*" & Txt_log_job.Value & "*"""
End If
If ((Chk_log_incident) And Not (IsNull(Txt_log_incident.Value))) Then
strWhere = strWhere & " AND [Opportunities].[Customer Enquiry Reference] Like """ & "*" & Txt_log_incident.Value & "*"""
End If

If (strWhere <> "") Then strWhere = "(" & Mid(strWhere, 6) & ")"

If (Chk_log_date) Then
If Not (IsNull(DT_log_date1.Value)) Then
strDate = " AND tblLog.Date >= " & _
"#" & Format$(DT_log_date1.Value, "mm/dd/yyyy") & "#"
End If
If Not (IsNull(DT_log_date2.Value)) Then
strDate = strDate & " AND tblLog.Date <= " & _
"#" & Format$(DT_log_date2.Value, "mm/dd/yyyy") & "#"
End If
If (Check191) Then
If Not (IsNull(ActiveXCtl194.Value)) Then
strDate = " AND [Opportunities].[Enquiry Date] >= " & _
"#" & Format$(ActiveXCtl194.Value, "mm/dd/yyyy") & "#"
End If
If Not (IsNull(ActiveXCtl195.Value)) Then
strDate = strDate & " AND [Opportunities].Date <= " & _
"#" & Format$(ActiveXCtl195.Value, "mm/dd/yyyy") & "#"
End If
End If
If (strWhere <> "") Then
strWhere = strWhere & strDate
Else
strWhere = Mid(strDate, 6)
End If
If (strWhere <> "") Then strSQL = strSQL & "WHERE " & strWhere

If Frm_sort.Value = 1 Then
strSQL = strSQL & " ORDER BY [Opportunities].[# ID] ASC, [Opportunities].Date DESC"
Else
strSQL = strSQL & " ORDER BY [Opportunities].Date DESC, [Opportunities].[# ID] ASC"
End If

'If (Chk_log_date) Then
' If Not (IsNull(DT_log_date1.Value)) Then
' strWhere = strWhere & " AND tblLog.Date >= " & _
' "#" & Format$(DT_log_date1.Value, "mm/dd/yyyy") & "#"
' End If
' If Not (IsNull(DT_log_date2.Value)) Then
' strWhere = strWhere & " AND tblLog.Date <= " & _
' "#" & Format$(DT_log_date2.Value, "mm/dd/yyyy") & "#"
' End If
'End If

'If (strWhere <> "") Then strSQL = strSQL & "WHERE " & Mid(strWhere, 6)

Set qdf = CurrentDb.QueryDefs("[Opportunities Extended]")
qdf.SQL = strSQL
qdf.Close
Forms![frmSiteLog]![New Enquiry].Form.RecordSource = ""
Forms![frmSiteLog]![New Enquiry].Form.RecordSource = "[Opportunities Extended]"
End If
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom