Pop-up Search Tool will not pull in data (1 Viewer)

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:49
Joined
Aug 30, 2003
Messages
36,125
What is the result of the debug.print? Does that SQL work in a new query?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:49
Joined
Aug 30, 2003
Messages
36,125
It won't open by itself when that code runs, you have to open it (sorry if that's a stupid comment, couldn't tell if that's what you expected).
 

Mr. Southern

Registered User.
Local time
Today, 07:49
Joined
Aug 29, 2019
Messages
90
It won't open by itself when that code runs, you have to open it (sorry if that's a stupid comment, couldn't tell if that's what you expected).

No its not a stupid comment. I'm trying to teach myself how to do this and you guys are very helpful. I try to open it but nothing happens.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:49
Joined
Aug 30, 2003
Messages
36,125
Alt-F11 should open the VBA editor. Then Ctl-G or View/Immediate Window should show the Immediate window if it isn't already showing. If that doesn't work, I've seen it open where it was so tight to the bottom of the window it was hard to see. If that's the case, hovering your mouse around there may show the double arrow that will let you drag it up.
 

Mr. Southern

Registered User.
Local time
Today, 07:49
Joined
Aug 29, 2019
Messages
90
Alt-F11 should open the VBA editor. Then Ctl-G or View/Immediate Window should show the Immediate window if it isn't already showing. If that doesn't work, I've seen it open where it was so tight to the bottom of the window it was hard to see. If that's the case, hovering your mouse around there may show the double arrow that will let you drag it up.

wow... it was tight. It must be because I am usually on a bigger screen. If I use the code I was trying it brings back:
Code:
SELECT qry_ChainDetail.Cust, qry_ChainDetail.Name, qry_ChainDetail.Address, qry_ChainDetail.City FROM qry_ChainDetail WHERE & strSearch ORDER BY qry_ChainDetail.[Cust];
SELECT qry_ChainDetail.Cust, qry_ChainDetail.Name, qry_ChainDetail.Address, qry_ChainDetail.City FROM qry_ChainDetail WHERE & strSearch ORDER BY qry_ChainDetail.[Cust];

If I use what MajP suggested I get back:
Code:
SELECT Cust, [Name], Address, City FROM qry_ChainDetail WHERE & strSearch ORDER BY [Cust]
SELECT Cust, [Name], Address, City FROM qry_ChainDetail WHERE & strSearch ORDER BY [Cust]
SELECT Cust, [Name], Address, City FROM qry_ChainDetail WHERE & strSearch ORDER BY [Cust]
 

Mr. Southern

Registered User.
Local time
Today, 07:49
Joined
Aug 29, 2019
Messages
90
How about a couple helper functions to make this way easier
Code:
Private Sub cmdSearch_Click()
Dim strSearch As String
Dim strSQL As String
Dim FieldName As String
strSearch = Me.txtSearch.Value

Select Case Me.grpWhere.Value
  Case 1 'Customer Number
     FieldName = "[Cust]"
     Select Case Me.grpHow.Value
       Case 1 'Starts With
         strSearch = GetBegin(FieldName, strSearch)
        Case 2 'Ends With
          strSearch = GetEnd(FieldName, strSearch)
        Case 3 'Contains
          strSearch = getBoth(FieldName, strSearch)
      End Select
  Case 2 'Customer Name
    FieldName = "[Name]"
    Select Case Me.grpHow.Value
       Case 1 'Starts With
         strSearch = GetBegin(FieldName, strSearch)
       Case 2 'Ends With
         strSearch = GetEnd(FieldName, strSearch)
       Case 3 'Contains
         strSearch = getBoth(FieldName, strSearch)
    End Select
  Case 3 'Both
    Select Case Me.grpHow.Value
       Case 1 'Starts With
          strSearch = GetBegin("[Cust]", strSearch) & " OR " & GetBegin("[Name]", strSearch)
       Case 2 'Ends With
          strSearch = GetEnd("[Cust]", strSearch) & " OR " & GetEnd("[Name]", strSearch)
        Case 3 'Contains
          strSearch = getBoth("[Cust]", strSearch) & " OR " & getBoth("[Name]", strSearch)
    End Select
End Select
strSQL = "SELECT Cust, [Name], Address, City FROM qry_ChainDetail WHERE & strSearch ORDER BY [Cust]"
With Me.lstSearch
  .RowSource = strSQL
  .Requery
  Debug.Print strSQL
End With
End Sub

Public Function GetEnd(FieldName, strSearch As String) As String
  GetEnd = FieldName & " like '" & strSearch & "#'"
End Function

Public Function GetBegin(FieldName, strSearch As String) As String
  GetBegin = FieldName & " like '*" & strSearch & "'"
End Function

Public Function getBoth(FieldName, strSearch As String) As String
  getBoth = FieldName & " like '*" & strSearch & "#'"
End Function

when you post code, select the code then hit the # side in the message box to format nicely.

What do those public functions do?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:49
Joined
Aug 30, 2003
Messages
36,125
You can see that strSearch isn't getting interpreted into its value. You need to terminate your string before concatenating the variable.

"...WHERE " & strSearch & "..."
 

Mr. Southern

Registered User.
Local time
Today, 07:49
Joined
Aug 29, 2019
Messages
90
You can see that strSearch isn't getting interpreted into its value. You need to terminate your string before concatenating the variable.

"...WHERE " & strSearch & "..."

hmmm I understand what you mean but I'm not getting it.

Code:
FROM qry_ChainDetail" WHERE " & strSearch & "ORDER BY qry_ChainDetail.[Cust]"

It says im getting an end of statement at my WHERE
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:49
Joined
Aug 30, 2003
Messages
36,125
Delete the quotes before WHERE. The ellipsis replaced the rest of the string.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:49
Joined
Aug 30, 2003
Messages
36,125
Happy to help bestie! :p
 

Users who are viewing this thread

Top Bottom