Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101

    Search as you type, in combo box

    Hi Guys, I have been following this thread https://www.accessforums.net/showthread.php?t=48811 to update a combo box to allow for searching/filtering records as the user types.



    I have on an invoice line item form a combo box, the row source behind the combo is:


    SELECT DISTINCTROW tblPrices.productID, products.Item, tblPrices.price, tblinventory.Sumofqty, tblPrices.CustID, tblPrices.available
    FROM ((products INNER JOIN tblPrices ON products.productID = tblPrices.productID) INNER JOIN tblUnits ON products.unitsID = tblUnits.unitsID) LEFT JOIN tblinventory ON tblPrices.productID = tblinventory.productID
    WHERE (((products.Item) Like "*" & Me.cboProducts.Text & "*') AND ((tblPrices.CustID)=[Forms]![frmOrderPlacement]![txtCustID]) AND ((tblPrices.available)=False))
    ORDER BY products.Item

    My issue is that this errors here: & Me.cboProducts.Text & "*' where I am trying to link this to the combo box, so need to add something like: If Len(Me.cboProducts.Text) > 0 Then But do not know how to add this into the query designer of access:


    Can anyone help with this please ?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    instead of running N queries as they type,
    why not run 1 query when they finish typing?

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Me.cboProducts.Text
    You cannot use text property in a query. You could use .Value but most don't bother as it is the default property of several control types, one of which is the textbox. Also, you cannot use Me in a query either - only in code behind the form or report. Use the same syntax as you did for tblPrices.CustID
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    Quote Originally Posted by Micron View Post
    Me.cboProducts.Text
    You cannot use text property in a query. You could use .Value but most don't bother as it is the default property of several control types, one of which is the textbox. Also, you cannot use Me in a query either - only in code behind the form or report. Use the same syntax as you did for tblPrices.CustID
    Thanks for that feedback, I have as suggested modified the row source:

    SELECT DISTINCTROW tblPrices.productID, products.Item, tblPrices.price, tblinventory.Sumofqty, tblPrices.CustID, tblPrices.available
    FROM ((products INNER JOIN tblPrices ON products.productID = tblPrices.productID) INNER JOIN tblUnits ON products.unitsID = tblUnits.unitsID) LEFT JOIN tblinventory ON tblPrices.productID = tblinventory.productID
    WHERE (((products.Item) Like "*" & [Forms]![frmOrderItems]![cboProducts] & "*") AND ((tblPrices.CustID)=[Forms]![frmOrderPlacement]![txtCustID]) AND ((tblPrices.available)=False))
    ORDER BY products.Item;

    However, this now opens a parameter box:

    Click image for larger version. 

Name:	search combo01.JPG 
Views:	32 
Size:	63.9 KB 
ID:	47046

    if I enter something valid, it then allows me to return to the combo control and shows items that match the term added, and remains for the next items in the order, so assume I need to add this query on the onChange event and not in the row source?

    I Have tried onChange event, that did not work

  5. #5
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    instead of running N queries as they type,
    why not run 1 query when they finish typing?

    sorry, I don't understand what you mean, can you clarify?

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    You're executing that sql in code or it's a query? If query, the form or control name is likely misspelled or the referenced form isn't open. You show 2 form names there - they must both be open, but not necessary to be visible. If vba code, you'll need to declare and set one or more parameters.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    Quote Originally Posted by Micron View Post
    You're executing that sql in code or it's a query? If query, the form or control name is likely misspelled or the referenced form isn't open. You show 2 form names there - they must both be open, but not necessary to be visible. If vba code, you'll need to declare and set one or more parameters.
    Hi Micron,

    The SQL is via query designer, both forms are open, the combo exists on frmOrderItems I have checked the names and they are correct, no misspelling., but it still opens the parameter box and once a value is used, that then persists for the next line entry. So I need to stop the parameter box opening, and also need to clear for the next line item!

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Sorry, Access does not prompt for a value if it knows what it is?
    Common error is mispelling, then syntax. So if that combo is on a subform, the syntax is all wrong?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    perhaps try in the cboProducts change event

    Code:
    cboProducts.rowsource="SELECT DISTINCTROW tblPrices.productID, products.Item, tblPrices.price, tblinventory.Sumofqty, tblPrices.CustID, tblPrices.available" & _
                          " FROM ((products INNER JOIN tblPrices ON products.productID = tblPrices.productID) INNER JOIN tblUnits ON products.unitsID = tblUnits.unitsID) LEFT JOIN tblinventory ON tblPrices.productID = tblinventory.productID" & _
                          " WHERE products.Item Like '*' & [cboProducts].text & '*' AND tblPrices.CustID)=" & me.[txtCustID] & " AND tblPrices.available=False" & _
                          " ORDER BY products.Item"
    
    Edit: you may need to cater for when a user types something then backspaces to clear the entry so there is a zls or null value, note also the change for "*" to '*'
    Edit2: perhaps make it conditional on users typing more than three characters or trigger a timer event on each keypress and if no further timing after say 1/2 second (timer interval=500) the timer event populates the combo rowsource

  10. #10
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    Quote Originally Posted by Ajax View Post
    perhaps try in the cboProducts change event

    Code:
    cboProducts.rowsource="SELECT DISTINCTROW tblPrices.productID, products.Item, tblPrices.price, tblinventory.Sumofqty, tblPrices.CustID, tblPrices.available" & _
                          " FROM ((products INNER JOIN tblPrices ON products.productID = tblPrices.productID) INNER JOIN tblUnits ON products.unitsID = tblUnits.unitsID) LEFT JOIN tblinventory ON tblPrices.productID = tblinventory.productID" & _
                          " WHERE products.Item Like '*' & [cboProducts].text & '*' AND tblPrices.CustID)=" & me.[txtCustID] & " AND tblPrices.available=False" & _
                          " ORDER BY products.Item"
    
    Edit: you may need to cater for when a user types something then backspaces to clear the entry so there is a zls or null value, note also the change for "*" to '*'
    Edit2: perhaps make it conditional on users typing more than three characters or trigger a timer event on each keypress and if no further timing after say 1/2 second (timer interval=500) the timer event populates the combo rowsource
    Thanks for that feedback and suggestions, when I attempt this I cam getting the error message:
    Click image for larger version. 

Name:	search combo02.JPG 
Views:	25 
Size:	25.3 KB 
ID:	47052

    I've tried various alterations, but no look, can't spot the closing error?

    I will try your edit suggestions in edits 1 & 2 once I have resolved this.

    Thank you

  11. #11
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    can't spot the closing error?
    my bad I left a closing bracket in after tblPrices.CustID


  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    @WGM, good point about the subform.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    Quote Originally Posted by Ajax View Post
    my bad I left a closing bracket in after tblPrices.CustID

    Hi Ajax, thanks for that, I did try removing the closing, and have tried it after various positions but none are working ... sorry if I appear dumb, just cant close the statement, can you advise please?

  14. #14
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    Quote Originally Posted by Ajax View Post
    my bad I left a closing bracket in after <font color="#333333"><em>tblPrices.CustID<br>
    <br>
    </em></font>
    <br>
    <br>Hi Ajax,&nbsp; thanks for that, I did try removing the closing, and have tried it after various positions but none are working ... sorry if I appear dumb, just cant close the statement, can you advise please?&nbsp;

  15. #15
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    provide the actual code you are using together with any error messages as I cannot see anything wrong with the code I provided once the extra ) is taken out - the previous error message you provided was quite clear as to what and where the problem was

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

Similar Threads

  1. Search as you type in Combo Box
    By Grandad in forum Access
    Replies: 29
    Last Post: 07-11-2020, 12:31 PM
  2. Search combo box as I type inside it
    By bilalo in forum Forms
    Replies: 8
    Last Post: 07-14-2019, 09:03 PM
  3. Replies: 4
    Last Post: 01-31-2018, 10:37 AM
  4. Search as you type - Combo box
    By lateral in forum Programming
    Replies: 20
    Last Post: 01-29-2015, 12:16 AM
  5. search as you type in combo box
    By pratim09 in forum Forms
    Replies: 3
    Last Post: 08-05-2011, 07:46 AM

Tags for this Thread

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