UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Filter a form based on combo boxes    
 
   
swaziman1
post Dec 18 2007, 04:29 AM
Post #1

UtterAccess Ruler
Posts: 1,063



Hi,

I have a form which has a table as a record source , I have 4 combo boxes (FName,LName,City,Country)on my form with a rowsource of 4 different fields in the table, what I would like is that when a user makes a selection in the combo boxes the form filters accordingly.I can do this by changeing the record source on the after update event on the combobox, however I want the form to filter on any of the comboboxes, eg. if a user makes a selection in FName and City then it should show all those records or alternatively if the user makes a selection on Country only it should change the record source accordingly.I am trying the following code but the problem is that it assumes the other combo boxes have selections, please let me know if this doesn't make sense, any help would be greatly appreciated.
Thanks

CODE
  

Dim strSQLSF As String

    strSQLSF = " SELECT * FROM tblMainData "
    strSQLSF = strSQLSF & " WHERE tblMainData.FName = '" & cmbFName & "' And  "
    strSQLSF = strSQLSF & " tblMainData.LName = '" & cmbLName & "' And "
    strSQLSF = strSQLSF & " tblMainData.City = '" & cmbCity & "'"


    Me.RecordSource = strSQLSF
Go to the top of the page
 
+
Peter46
post Dec 18 2007, 06:24 AM
Post #2

UtterAccess VIP
Posts: 7,394
From: Oadby Leics, UK



Dim strSQLSF As String
strSQLSF = " SELECT * FROM tblMainData "
strSQLSF = strSQLSF & " WHERE (tblMainData.FName = '" & cmbFName & "' or Isnull(Forms!formname!cmbFanme) ) And "
strSQLSF = strSQLSF & "( tblMainData.LName = '" & cmbLName & "' or Isnull(forms!formnname!cmbLname))And "
strSQLSF = strSQLSF & " (tblMainData.City = '" & cmbCity & "' Or Isnull(forms!formname!cmbCity)) "
Me.RecordSource = strSQLSF
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th May 2013 - 03:36 AM