Button to refresh or reload form (1 Viewer)

shafara7

Registered User
Joined
May 8, 2017
Messages
118
I have a few comboboxes with filtering type and a subform and when I am done with my work, I want the form to be reset as if it is just loaded.
I want to have a refresh button on my form so that when I click it, it will return the form to it's original untouched form.

I tried adding a button and set the category to Form Operations and the Actions to Refresh Form Data. But it does not work. An error occured saying The Action 'Refresh' is not yet available.

Any idea why? Is there any VBA codes for this?
 

JHB

Have been here a while
Joined
Jun 17, 2012
Messages
7,720
You could try a requery.
Code:
Me.Requery
Else close the form and open it again using VBA code.
Code:
DoCmd.Close
DoCmd.OpenForm "YourFormName"
 

Cronk

Registered User
Joined
Jul 4, 2013
Messages
2,235
If the parent form is not bound to a data source and all that is required is to set unbound filtering combos backed to their "original untouched form" then on your button's code, for each filtering control put

me.MyCombo = [original value]
or if they are blank
me.MyCombo=null
 

shafara7

Registered User
Joined
May 8, 2017
Messages
118
JHB, I tried Me.Requery but nothing happend. Closing and opening it again is also not an option because that is what I have been doing before. That is why I need a button to simplify the work.

Cronk, I tried the me.MyCombo=null code, but it will only reset my combobox to Null, my subform and listbox is not reset back even though it is suppose to be controlled by that combobox.
 

isladogs

CID Moderator
Staff member
Joined
Jan 14, 2017
Messages
12,337
Sometimes you do have to specify items separately e.g. use one or more of the following

Code:
'form/subform
Me.Requery
Me.subformName.Requery 

'combo boxes
Me.combobox1=""
Me.combobox2=""

'listboxes
Me.listbox = Null
Me.listbox.Requery

'multiselect listboxes
For Each varItem In Me.Listbox.ItemsSelected
        Me.Listbox.Items.Selected(varItem) = False
    Next varItem

'or ....
For I = 0 To Me.Listbox.ListCount - 1
        Me.Listbox..Selected(I) = False
Next
If all else fails then do close & reopen the form but use Application.Echo to stop screen updating until its complete

Code:
Application.Echo False
DoCmd.Close 
DoCmd.OpenForm "FormName"
Application.Echo True
That way you won't even notice the reloading & its quick
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom