Results 1 to 6 of 6
  1. #1
    inthu is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2014
    Posts
    2

    Mulity Texbox Filtering not working

    Option Compare Database

    Private Sub cmdSearch_Click()
    On Error GoTo errr


    Me.FloorMaintanance_subform.Form.RecordSource = SQL = "SELECT FloorMaintanance.* from FloorMaintanance " & BuildFilter
    Me.FloorMaintanance_subform.Requery
    Exit Sub
    errr:


    MsgBox Err.Description
    End Sub


    Private Function BuildFilter() As Variant
    Dim varWhere As Variant
    varWhere = Null


    If Me.txtFloor > "" Then
    varWhere = varWhere & "[FloorNO] like " & Me.txtFloor & " AND "
    End If


    If Me.txtstatus > "" Then
    varWhere = varWhere & "[Status] like " & Me.txtstatus & " AND "
    End If


    If Me.txtCat > "" Then
    varWhere = varWhere & "[Catergory] like " & Me.txtCat & " AND "
    End If


    If IsNull(varWhere) Then
    varWhere = ""
    Else
    varWhere = "WHERE" & varWhere

    If Right(varWhere, 3) = "AND" Then
    varWhere = Left(varWhere, Len(varWhere) - 3)
    End If
    End If

    BuildFilter = varWhere
    End Function

    hi friends
    this coding not working i dnt know y
    plz solve my problem
    thanks
    inthu

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What is the problem? How is it not working? How do you know it is not working?

  3. #3
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Did a quest test. It looks like the check for "AND" failed because you padded with a blank at the end. This should fix it.

    If Right(RTRIM(varWhere), 3) = "AND" Then
    varWhere = Left(varWhere, Len(varWhere) - 3)
    End If
    End If

  4. #4
    inthu is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2014
    Posts
    2
    because i run this form i click cmdSearch. there is no action i ll happen in the view page

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    place a debug line at the end of the function like this

    BuildFilter = varWhere
    debug.print varWhere
    End Function

    Look in the immediate window and paste the result here for us to look at. Immediate window can be viewed using Ctrl+G on your keyboard. I did not test the code, but I see a WHERE with quotes and no spaces. Also I still use + with variants rather than ampersands. And I am not sure what = SQL = is about.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If Me.txtstatus and Me.txtCat are text strings, then they need to be delimited.

    For info about delimiters, see http://allenbrowne.com/binary/Access...Chapter_07.pdf

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Formating a texbox
    By alextol in forum Forms
    Replies: 23
    Last Post: 10-01-2013, 11:50 AM
  2. Replies: 3
    Last Post: 08-28-2013, 11:08 PM
  3. Working & Filtering Dates
    By the_reg in forum Access
    Replies: 2
    Last Post: 07-26-2013, 07:35 AM
  4. Combobox with texbox as criteria
    By putte11 in forum Forms
    Replies: 5
    Last Post: 12-10-2012, 05:32 PM
  5. click label -> append text to texbox
    By cnstarz in forum Access
    Replies: 5
    Last Post: 06-15-2011, 06:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums