I have Access 2016. I would like to know how I can create a query in code in VBA and then have it open in an Access form.
I tried:
Dim strSQL1 As String
Dim qdf As DAO.QueryDef
strSQL1 = "SELECT tblSightings2001.Species, Species.LatinName, Species.BirdGroups, tblSightings2001.Numbers, tblSightings2001.Place, tblSightings2001.DateSighted " & "FROM Species INNER JOIN tblSightings2001 ON Species.Species = tblSightings2001.Species " & " WHERE (((tblSightings2001.DateSighted) Between #1/1/2012# And #12/31/2012#)) " & " ORDER BY tblSightings2001.DateSighted; "
Set qdf = CurrentDb.QueryDefs("qryDummy")
qdf.SQL = strSQL1
DoCmd.OpenQuery "qryDummy"
Set qdf = Nothing
but it do not work.