Share via

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

Maxine Nietz 1 Reputation point
2026-02-05T16:32:12.98+00:00

In a table, OrderHistory, PONo is a text field; PID is an autonumber (key) field. POS is a text box on a form POSearchF.

 

I have the following code:

Dim lsql As DAO.Recordset

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

 

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

Microsoft 365 and Office | Access | For home | Windows

1 answer

Sort by: Most helpful
  1. Karl Donaubauer 3,191 Reputation points
    2026-02-06T00:17:38.6166667+00:00

    Hi,

    It could e.g. look like this:

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strSQL As String
    
    Set db = Currentdb
    strSQL = "SELECT PID, PONo FROM OrderHistory WHERE PONo = '" & Forms!POSearchF!POS & "'"
    Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    

    Servus
    Karl
    Access Forever, News, DevCon
    Access-Entwickler-Konferenz AEK

    0 comments No comments

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.