Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Is there a way to add a error check?
    What's the error? What do you want to happen when TxtKeywords is blank?

  2. #17
    sparker75 is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jul 2018
    Posts
    107
    The error is that the query filters are all removed. I would just like to use the original query when the search is blank.

  3. #18
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    The error is that the query filters are all removed.
    Removed? How is that possible? There is no code to modify the query.
    This code will do so:
    Code:
    If isnull(TxtKeywords) then
        SQL = "Select....  "      'Original query
    else
       SQL = "Select...   "       'Filter query
    end if
    me.recordsource = SQL
    Last edited by davegri; 09-26-2018 at 11:56 AM. Reason: clarif

  4. #19
    sparker75 is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jul 2018
    Posts
    107
    Works! Thank you very much

  5. #20
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You do not have parentheses as shown in my example in post 11.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #21
    sparker75 is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jul 2018
    Posts
    107
    This is what I have now. It seems to work

    Private Sub Command433_Click()
    Dim SQL As String
    If IsNull(TxtKeywords) Then
    SQL = "SELECT tblOrderNotifications.CreatedOn, tblOrderDetails.WBS, tblOrderNotifications.Notification, tblOrderDetails.Revision, tblOrderDetails.OrderType, tblOrderDetails.OrderNum, tblOrderDetails.Sortfield, tblOrderNotifications.CreatedBy, tblOrderStatus.AssignUsername, tblOrderDetails.PlannerGroup, tblObjectStatus.Status, tblObjectPriority.Descripton, tblProjectStatus.DateClosed, tblOrderStatus.Project FROM tblOrderNotifications LEFT JOIN (tblObjectStatus RIGHT JOIN (tblObjectPriority RIGHT JOIN (tblProjectStatus RIGHT JOIN (tblOrderDetails LEFT JOIN tblOrderStatus ON tblOrderDetails.OrderNum = tblOrderStatus.OrderNum) ON tblProjectStatus.ProjectNum = tblOrderStatus.Project) ON tblObjectPriority.PrioID = tblOrderStatus.PRIOID) ON tblObjectStatus.SID = tblOrderStatus.SID) ON tblOrderNotifications.Notification = tblOrderDetails.Notification " _
    & "WHERE tblProjectStatus.DateClosed Is Null " _
    & "Order BY tblOrderNotifications.CreatedOn DESC"
    Else
    SQL = "SELECT tblOrderNotifications.CreatedOn, tblOrderDetails.WBS, tblOrderNotifications.Notification, tblOrderDetails.Revision, tblOrderDetails.OrderType, tblOrderDetails.OrderNum, tblOrderDetails.Sortfield, tblOrderNotifications.CreatedBy, tblOrderStatus.AssignUsername, tblOrderDetails.PlannerGroup, tblObjectStatus.Status, tblObjectPriority.Descripton, tblProjectStatus.DateClosed, tblOrderStatus.Project FROM tblOrderNotifications LEFT JOIN (tblObjectStatus RIGHT JOIN (tblObjectPriority RIGHT JOIN (tblProjectStatus RIGHT JOIN (tblOrderDetails LEFT JOIN tblOrderStatus ON tblOrderDetails.OrderNum = tblOrderStatus.OrderNum) ON tblProjectStatus.ProjectNum = tblOrderStatus.Project) ON tblObjectPriority.PrioID = tblOrderStatus.PRIOID) ON tblObjectStatus.SID = tblOrderStatus.SID) ON tblOrderNotifications.Notification = tblOrderDetails.Notification " _
    & "WHERE tblProjectStatus.DateClosed Is Null " _
    & "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.Revision) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Or (tblOrderDetails.OrderType) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Or (tblOrderNotifications.CreatedBy) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Or (tblOrderDetails.PlannerGroup) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Or (tblOrderStatus.AssignUsername) LIKE '*" & Me.TxtKeywords & "*' " _
    & "Order BY tblOrderNotifications.CreatedOn DESC"
    End If
    Me.RecordSource = SQL
    Me.Requery
    End Sub

  7. #22
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Glad you got it working. Good luck with the rest of the project!

  8. #23
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    It should also work with the syntax (corrected parentheses) I suggested without the If Then. Should even be able to do dynamic parameterized query and eliminate VBA setting RecordSource.

    However, are you sure wildcard on number fields is giving expected results? LIKE "*1*" will return anything with the digit 1 : 1, 10, 11, 12 … 100, etc.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. CHECK CONSTRAINT causing Syntax Error?
    By AishlinnAnne in forum SQL Server
    Replies: 18
    Last Post: 09-13-2016, 12:42 PM
  2. Replies: 5
    Last Post: 06-26-2014, 12:52 PM
  3. Replies: 4
    Last Post: 02-03-2014, 12:16 PM
  4. Replies: 13
    Last Post: 04-17-2013, 04:17 PM
  5. Replies: 3
    Last Post: 10-25-2012, 10:04 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