I have 2 forms in MS Access. One is an overview form as an endless form, the other shows details of the single records. The overview form gets its content by a custom SQL passthrough query on opening:
Dim strSQL As String
strSQL = "SELECT DISTINCT tbl_Parts.strPart, Title, Comment FROM [tbl_Parts] inner JOIN [tbl_PartModules] ON tbl_Parts.strPart = tbl_PartModules.strPart ORDER BY tbl_Parts.strPart DESC"
Dim qdf As DAO.QueryDef, rst As DAO.Recordset
Set qdf = CurrentDb.CreateQueryDef("")
Dim strTmpConnQDF As String
strTmpConnQDF = CStr(Application.TempVars("tempvar_StrCnxn"))
qdf.Connect = strTmpConnQDF
qdf.sql = strSQL
qdf.ReturnsRecords = True
Set rst = qdf.OpenRecordset
Set Forms![frm_PartsOverview].Recordset = rst
Forms![frm_PartsOverview].Requery
'No rst.Close to have the data still in the Form!
Set qdf = Nothing
Within that overview, buttons can be used to change the underlying SQL query to show different records.
Each record has a "show details" button in the endless form which opens the detail form.
Within the detail form, I can change the data of the underlying record. After closing this form, I want to keep all settings (record selection, SQL query data) that were before opening the detail form. But I also want to update the underlying data, showing the changes made in the detail form also on the overview form.
I tried this code with the "hide" button of the detail form, but this does not work:
Forms!frm_PartsDetail.Visible = False
Forms!frm_PartsOverview.Recalc
Forms!frm_PartsOverview.Refresh
Forms!frm_PartsOverview.Requery
I tried all three variants (Recalc, Frequery, Refresh) but none of them did the trick. I guess its because of the way I assign the SQL query as the recordsource of the form. But how to update the recordsource, keeping all settings like they were before entering the detail form?