How might I use the sql string here as the Record Source for my Form?
Until using parameters I would get the sql, then set the Forms recordsource to the queryName e.g.
But now sql$ will contain "p0" and fail.
Code:
Function GetTitleMatch(sTitle) As DAO.Recordset
Dim sql As String
sql = "SELECT " & MyCompany & ".Artist, " & MyCompany & ".Title, " & MyCompany & ".Label, " & MyCompany & ".Year "
sql = sql & "FROM [" & MyCompany & "] "
sql = sql & " WHERE " & MyCompany & ".Title Like p0;"
With CurrentDb.CreateQueryDef("", sql)
.Parameters("p0") = SplitIt(sTitle)
Set GetTitleMatch = .OpenRecordset
.Close
End With
End Function
Code:
Dim MyQuery As QueryDef
Set MyQuery = db.QueryDefs(queryName)
MyQuery.sql = sql
DoCmd.OpenForm "TheForm", acFormDS, , stLinkCriteria