Avatar of Issa S.
Issa S.
 asked on

What is the VBA syntax for Refreshing the form in the After Update event of one of its controls ?

Hi All,,,

Poor me !"in VBA"....lol.

What is the VBA syntax for Refreshing the form in the After Update event of one of its controls ?
Microsoft Access

Avatar of undefined
Last Comment
Issa S.

8/22/2022 - Mon
Dale Fye

You would not normally need to "refresh" a form after updating a single control, that control would normally display the value you entered.

However, if you are dealing with some form of cascading controls (where one list or combo box depends on the value of another), then you might try something like:

Private Sub cboOne_AfterUpdate

    me.cbo_Two.Requery

    'if you have more than one other control that is dependent, or cbo_Three 
    'is dependent upon cbo_Two then you would also need to requery that control
    me.cbo_Three.Requery

End Sub

Open in new window

Then you would requery cbo_Three in the AfterUpdate of cbo_Two.

HTH
Dale
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

IF ... you attempt to do this in the AU of a Control ... and the Form is Dirty (in edit mode) ... Access will at that moment attempt to Save your record - which is likely NOT desired at that moment.

Instead ... if necessary ... use the Form AfterUpdate event to do this ...
either
Me.Requery
or
Me.Refresh

depending on what you are trying to accomplish.
Issa S.

ASKER
Hi Dale,,,

That is to say: there is nothing like "Refresh Form".   Correct Me Pls.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

There are two options:

Me.Refresh  ' Refreshes the current existing dataset - but no new records other may have added

Me.Requery ' Refreshes entire recordsource, including any new records that may have been added.

That's it :-)
Dale Fye

As Joe indicates, you could use me.Refresh  but all that would refresh the recordset and overwrite your changes.

If you want to write that changed value to the table, then you need:

Me.Dirty = False

The Dirty property of the form gets set to True when the value of any control on the current record changes.  To actually write that data to the table, you must save the record  which can be done in a variety of ways:

1.  move off the record
2.  Docmd.RunCommand acCmdSave
3.  Me.Dirty = false

#1 occurs automatically if you move off the current record or click on a control that is in a parent or subform.

HTH
Dale
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

"but all that would refresh the recordset and overwrite your changes."
Not after the record has been saved ...
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Dale Fye

Joe,

The OP didn't say the record was saved.  the question was (emphasis mine):

"What is the VBA syntax for Refreshing the form in the After Update event of one of its controls ? "
ASKER CERTIFIED SOLUTION
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Issa S.

ASKER
Lovely Joe & Dale.

Although I read of a lot about these thing but I never understood these differences as clear as from you now.

Many Many Thanks
Issa S.

ASKER
Very Helpfullllll
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy