I am sure that someone has a different way to do this, so please set me on the right path if this isn't the best method.
In MS Access I have different user types that all have different dashboards. All of these users can press a button on their dashboard to get a common overlay to enter a new record. Upon hitting save on the overlay, I need to refresh the subform on the dashboard with the new records. I have used vba that looks for open forms and then refreshes based on the form that is open, but I don't like this method because each time I create a new user type I have to remember to go back and update the code to look for this new dashboard. More recently I tried updating an unbound textbox on the overlay with the name of the form/subfrm that needs to be update, but I can't seem to get that to run correctly.
Here is my VBA that is run upon trying to save the record and update the correct form. (Note me.txtFrmRefresh is my unbound textbox)
Dim ctlFrmRefresh As Control
Set ctlFrmRefresh = me.txtFrmRefresh
ctlFrmRefresh.Form.Recordset.Requery
DoCmd.Close acForm, "frmClaimNew", acSaveNo
When I run this, get the following error "You entered an expression that has an invalid reference to the property form/report.
I know that the text in the unbound textbox is correct because I can change "me.txtFrmRefresh" to the form name and it works correctly.
CodePudding user response:
You can try this code to requery a form
To requery a Form:
Forms!FormName!Requery Forms(“FormNam”).Requery Forms!FormName!SubformControl!Form!Tequery (if it’s a subform)
CodePudding user response:
So I was able to get Eval to work, but it kept throwing an Object Required error. Ended up having to go back to my old way here I have an IF statement look for the dashboard that is open and then execute the refresh based off of that.
If CurrentProject.AllForms(strFrmAdmnRefresh).IsLoaded Then
Set ctlFrmAdmnRefresh = Forms!frmAdmnDshbd.navAdmnDshbd.Form!subfrmAdmnNavClaims
ctlFrmAdmnRefresh.Form.Recordset.Requery