I manage a Microsoft Access 2019 Database (owned by a customer) with a form (named Mainform) whose recordset source is a MySQL passthrough query (SELECT * FROM table_on_mysql_db); each recordset (shown directly on opening Mainform) is only readable and it has three fields: one of them, description, contains text.
On double clicking on description field, a small sized subform (name Subform, containing one textvalue field named keywordDescr, plus an OK button and a Cancel button) pops up.
If I enter some words in keywordDescr (i.e. anyword) and press OK, the following passthrough query
is being called and the resultset ouput must be displayed in Mainform (Subform still remains opened); unfortunately, the Mainform content is not updated accordingly to the above MySQL filtered query.
The following is the VBA code called on clicking the OK button in Subform (OK is the label and the button name is button_search_description):
Private sub button_search_description_Click()
on Error goto ErrDescr
Dim qdfc as DAO.QueryDef
Dim qryPT as String
Dim ODBC_STRING as String
Dim kwd as String
kwd = Me.keywordDescr
kwd = Replace(kwd, "*", "%") '(the customer is still used to entering Access wildcard rather than MySQL wildcard!)
kwd = Replace(kwd, "'", "\'")
ODBC_STRING = "ODBC;DSN=MY_DSN_NAME" ' it works!
qryPT = "SELECT * FROM table_on_mysql_db WHERE description LIKE '" & kwd & "'"
DoCmd.setWarnings = false
Set qdfc = DBEngine(0)(0).CreateQueryDef("")
With qdfc
.Connect = ODBC_STRING
.SQL = qryPT
.ReturnsRecords = True
Me.Parent.RecordSource = qryPT
End With
Set qdfc = nothing
DoCmd.setWarnings = true
ErrDescr:
Resume Next
End Sub
