Results 1 to 13 of 13
  1. #1
    sparker75 is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jul 2018
    Posts
    107

    Search Bar

    Hello,

    I would like to add a search bar on the top of my tabular form that will filter my list. Here is the code I have so far but it is giving me an Compile error: Method or data member not found


    Private Sub Command433_Click()
    Dim SQL As String

    SQL = "SELECT tblOrderNotifications.CreatedOn, tblOrderDetails.WBS, tblOrderNotifications.Notification, tblOrderDetails.Revision, tblOrderDetails.OrderType, tblOrderDetails.OrderNum, tblOrderDetails.Sortfield, tblOrderNotifications.CreatedBy, tblOrderDetails.PlannerGroup, tblObjectStatus.Status, tblObjectPriority.Descripton FROM tblOrderNotifications LEFT JOIN (tblObjectStatus RIGHT JOIN (tblObjectPriority RIGHT JOIN (tblOrderDetails LEFT JOIN tblOrderStatus ON tblOrderDetails.OrderNum = tblOrderStatus.OrderNum) ON tblObjectPriority.PrioID = tblOrderStatus.PRIOID) ON tblObjectStatus.SID = tblOrderStatus.SID) ON tblOrderNotifications.Notification = tblOrderDetails.Notification" _


    & "Where (OrderNum) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Order BY tblOrderDetails.[OrderNum]"

    Me.frmOrderStatus.Form.RecordSource.SQL
    Me.frmOrderStatus.Form.RecordSource.Requery

    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    dont use sql, make a query. The query shows all records.
    use a continuous form bound to the query.

    then when the user enters the item in the text box, filter the results:

    Code:
    sub txtFind_Afterupdate()
    const Q = """"
    
    if isNull(txtFind) then
       me.filterOn = false
    
    else
       me.filter = "[OrderNum] like '*"  & txtFind & "*'"
       me.filterOn = true
    end if

  3. #3
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You are missing a space at the end of here
    Code:
    blOrderNotifications.Notification = tblOrderDetails.Notification " _
    Add a Debug.Print SQL before the setting record source line and you'll be able to see the string as Access see it.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    sparker75 is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jul 2018
    Posts
    107
    Ranman. I would like this search box to look in more than one column and filter from there. They can search order number or WBS or Notification. I dont think your approach will work?

    Minty: I added the space but get the same result. Compile Error: Method or data member not found. The Me.frmOrderStatus.Form.RecordSource.SQL is highlighted

    QL = "SELECT tblOrderNotifications.CreatedOn, tblOrderDetails.WBS, tblOrderNotifications.Notification, tblOrderDetails.Revision, tblOrderDetails.OrderType, tblOrderDetails.OrderNum, tblOrderDetails.Sortfield, tblOrderNotifications.CreatedBy, tblOrderDetails.PlannerGroup, tblObjectStatus.Status, tblObjectPriority.Descripton FROM tblOrderNotifications LEFT JOIN (tblObjectStatus RIGHT JOIN (tblObjectPriority RIGHT JOIN (tblOrderDetails LEFT JOIN tblOrderStatus ON tblOrderDetails.OrderNum = tblOrderStatus.OrderNum) ON tblObjectPriority.PrioID = tblOrderStatus.PRIOID) ON tblObjectStatus.SID = tblOrderStatus.SID) ON tblOrderNotifications.Notification = tblOrderDetails.Notification " _
    & "Where (OrderNum) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Order BY tblOrderDetails.[OrderNum]"

    Click image for larger version. 

Name:	Capture.JPG 
Views:	24 
Size:	113.8 KB 
ID:	35289

  5. #5
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Actually unless you are trying to reference a sub form your syntax is incorrect
    Code:
    Me.frmOrderStatus.RecordSource = SQL
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    sparker75 is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jul 2018
    Posts
    107
    It is not a subform. What should the syntax be?

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    You omitted an equals sign before SQL

    Assuming this is run from the same form, replace these two lines
    Me.frmOrderStatus.Form.RecordSource.SQL
    Me.frmOrderStatus.Form.RecordSource.Requery

    With
    Me.RecordSource=SQL

    I don't think you'll need to requery but if you so then it's just:
    Me.Requery
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    sparker75 is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jul 2018
    Posts
    107
    I get this error now

    Click image for larger version. 

Name:	Capture.JPG 
Views:	24 
Size:	22.7 KB 
ID:	35290

  9. #9
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    a query will show you what is wrong.
    SQL will not.
    use a query.

  10. #10
    sparker75 is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jul 2018
    Posts
    107
    Ranman.

    will this filter through each column?

    sub txtFind_Afterupdate()
    const Q = """"

    if isNull(txtFind) then
    me.filterOn = false

    else
    me.filter = "[OrderNum] like '*" & txtFind & "*'"
    me.filterOn = true
    end if

  11. #11
    sparker75 is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jul 2018
    Posts
    107
    Ok. This is working now!!

    Private Sub Command433_Click()

    Dim SQL As String

    SQL = "SELECT tblOrderNotifications.CreatedOn, tblOrderDetails.WBS, tblOrderNotifications.Notification, tblOrderDetails.Revision, tblOrderDetails.OrderType, tblOrderDetails.OrderNum, tblOrderDetails.Sortfield, tblOrderNotifications.CreatedBy, tblOrderDetails.PlannerGroup, tblObjectStatus.Status, tblObjectPriority.Descripton FROM tblOrderNotifications LEFT JOIN (tblObjectStatus RIGHT JOIN (tblObjectPriority RIGHT JOIN (tblOrderDetails LEFT JOIN tblOrderStatus ON tblOrderDetails.OrderNum = tblOrderStatus.OrderNum) ON tblObjectPriority.PrioID = tblOrderStatus.PRIOID) ON tblObjectStatus.SID = tblOrderStatus.SID) ON tblOrderNotifications.Notification = tblOrderDetails.Notification " _
    & "Where (tblOrderDetails.OrderNum) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Order BY tblOrderDetails.[OrderNum]"
    Me.RecordSource = SQL

    End Sub




    I would like to search more than just OrderNum. How would I add multiple criteria?

    & "Where (tblOrderDetails.OrderNum) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Where (tblOrderDetails.WBS) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Where (tblOrderNotifications.Notification) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Where (tblOrderDetails.Revision) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Where (tblOrderDetails.OrderType) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Where (tblOrderDetails.Sortfield) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Where (tblOrderNotifications.CreatedBy) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Where (tblOrderDetails.PlannerGroup) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Where (tblObjectStatus.Status) LIKE '*" & Me.TxtKeywords & "*' " _


    I really appreciate your feedback and help!

  12. #12
    sparker75 is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jul 2018
    Posts
    107
    Sovled. Thank you!

  13. #13
    sparker75 is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jul 2018
    Posts
    107
    One last request.

    If I wanted to include '& "Where (tblOrderDetails.Revision) LIKE '*C*' " with the & "Where (tblOrderDetails.Revision) LIKE '*" & Me.TxtKeywords & "*' " _ So that Revisions would have to have a C or TxtKeyword

    This way the list will be limited to the C and what is typed in the search



    Here is the code as it stands.



    Private Sub Command433_Click()

    Dim SQL As String

    SQL = "SELECT tblOrderNotifications.CreatedOn, tblOrderDetails.WBS, tblOrderNotifications.Notification, tblOrderDetails.Revision, tblOrderDetails.OrderType, tblOrderDetails.OrderNum, tblOrderDetails.Sortfield, tblOrderNotifications.CreatedBy, tblOrderDetails.PlannerGroup, tblObjectStatus.Status, tblObjectPriority.Descripton FROM tblOrderNotifications LEFT JOIN (tblObjectStatus RIGHT JOIN (tblObjectPriority RIGHT JOIN (tblOrderDetails LEFT JOIN tblOrderStatus ON tblOrderDetails.OrderNum = tblOrderStatus.OrderNum) ON tblObjectPriority.PrioID = tblOrderStatus.PRIOID) ON tblObjectStatus.SID = tblOrderStatus.SID) ON tblOrderNotifications.Notification = tblOrderDetails.Notification " _
    & "Where (tblOrderDetails.Revision) LIKE '*" & Me.TxtKeywords & "*' " _
    & "And (tblOrderDetails.OrderNum) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Or (tblOrderDetails.WBS) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Or (tblOrderDetails.Sortfield) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Or (tblObjectStatus.Status) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Or (tblOrderNotifications.Notification) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Or (tblOrderDetails.OrderType) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Or (tblOrderNotifications.CreatedBy) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Or (tblOrderDetails.PlannerGroup) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Order BY tblOrderNotifications.CreatedOn DESC"
    '& "Where (tblOrderDetails.Revision) LIKE '*C*' "
    Me.RecordSource = SQL
    Me.Requery

    End Sub

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

Similar Threads

  1. Replies: 3
    Last Post: 08-21-2018, 03:11 PM
  2. Replies: 3
    Last Post: 09-12-2016, 11:49 AM
  3. Replies: 8
    Last Post: 09-02-2015, 03:00 PM
  4. Replies: 1
    Last Post: 03-26-2015, 11:08 AM
  5. Replies: 3
    Last Post: 01-04-2015, 06:09 PM

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