Cannot refresh a form (1 Viewer)

TasCat09

New member
Local time
Today, 18:36
Joined
Aug 7, 2016
Messages
10
Good morning

I was hoping someone could help me understand why my VBA code cannot refresh a userform.

I am using Access 2019 and have a simple database that includes a continuous form. Part of the form is a field to display a field from a table. The field is either set to no or yes and is displaying as expected. I am using this method as a workaround for allowing a user to select different records because I was not able to get checkbox controls to work on the continuous form.

I have a command button in the detail section of the continuous form that toggles the field between no and yes whenever the user clicks it. The field for a specific record changes from no to yes (or vice versa) correctly each time the user clicks the button but I cannot get the form to refresh (and show the new value) without manually clicking the refresh button or by selecting refresh all. I have tried a couple of things so far without success including the most obvious (i.e. adding '[Forms]![FormName].Refresh' in the code for the command button click event).

I have even tried putting 'me.refresh' in form events and then either triggering those events or calling that sub from within the command button click event but nothing (other than manually pressing the refresh button) seems to work.

I don't think it is relevant as the controls are all working fine and the fields update when I manually hit refresh but I have got the userform set as a snapshot recordset type as I essentially want the form to be read only.

Despite searching for an answer to this problem, I am completely stumped and would appreciate any help at all.
 

TasCat09

New member
Local time
Today, 18:36
Joined
Aug 7, 2016
Messages
10
My bad, syntax error. FYI, correct syntax was DoCmd.Requery (FormName) . Requery instead of Refresh but works great.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:36
Joined
Feb 19, 2002
Messages
43,223
I was hoping someone could help me understand why my VBA code cannot refresh a userform.
Access has its own version of forms and they are different from UserForms. Are you actually using a UserForm? I'm not even sure you can use a UserForm but if you are using one, you must use the appropriate method whatever it is.
I was not able to get checkbox controls to work on the continuous form.
Each row of a continuous form is an instance of the form. Access maintains only one set of properties for the form. Therefore, if the field is unbound, ALL rows will show the same value. If you want to select rows using a checkbox, you are going to have to add a new field to the table and use that. However, this becomes problematic in a multi-user environment if multiple people are trying to use the feature at the same time.

Did you add a field to the table that you are using to select the record? If you are trying to change the value of a field with VBA, you are going to have to run an update query to update the table since the snapshot is not updateable.

Both Refresh and Requery force Access to save the current record before either refreshing the values or retunning the RecordSource query from scratch. Refresh will not bring in new records and I think it might mark deleted records as #deleted#. Requery does what it says. It reruns the RecordSource query again so you get added records and updates to existing records as well as not seeing deleted records. Both methods are poor practice as a method of saving a form's bound record.
 

Users who are viewing this thread

Top Bottom