Share via

Trying to find a value

Maxine Nietz 1 Reputation point
2026-02-04T23:00:00.8366667+00:00

PONo is a text field; PID is an autonumber (key) field. POS is a text box on a form. PONoQ is a select query as follows:

SELECT OrderHistory.PONo, OrderHistory.PID FROM Purchases INNER JOIN OrderHistory ON Purchases.PID = OrderHistory.PID ORDER BY OrderHistory.PONo;

I have the following code:

Dim lsql As DAO.Recordset

Set lsql = "SELECT PONoQ.PID, PONoQ.PONo FROM PONoQ WHERE (((PONoQ.PONo) Like '' & [Forms]![POSearchF]![POS] & ''));"

I cannot get the query to run with single quotes or double quotes.

PLEASE HELP!!!

Thanks in advance.

Microsoft 365 and Office | Access | For education | Windows
0 comments No comments

1 answer

Sort by: Most helpful
  1. Austin-H 8,355 Reputation points Microsoft External Staff Moderator
    2026-02-05T05:42:47.7566667+00:00

    Hi Maxine Nietz

    Thank you for reaching out to the Microsoft Q&A Forum and for sharing the details of your issue.

    Based on your description, I tried to reproduce the scenario on my side, and it seems to work normally. You may try using an approach like the following: 

    Private Sub POS_AfterUpdate()
     
    Dim rs As DAO.Recordset
    Dim strSQL As String
     
    strSQL = "SELECT PONoQ.PID, PONoQ.PONo FROM PONoQ " & _
             "WHERE PONoQ.PONo Like '*" & Me.POS & "*';"
     
    Set rs = CurrentDb.OpenRecordset(strSQL)
     
    MsgBox rs.RecordCount
     
    rs.Close
    Set rs = Nothing
     
    End Sub
    

    User's image

    Could you please try this on your side and see if it works? 

    If I have misunderstood your scenario, please feel free to let me know and I’ll be happy to take another look.


    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.