Share via

Help Refreshing Form

Anonymous
2012-02-06T20:10:59+00:00

Hi,

I currently have a dlookup field that I want to refresh.  I tried to use the code from the refresh button into the database, but it doesn't work.  Even if I create the refresh button, it gives me an error saying that refresh isn't available or something.  The only way I can refresh is with the f5 key.  Do you know why this could be?  Also, how can I make the f5 automatically work within the form?

Thanks

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-02-08T02:43:28+00:00

Anyhow, even though I got this to work, I would like to know why it works in some forms and it didn't work in this form that I have?  Also, what did you mean by "text boxes do not have the Recalc method"?

"Refresh" means, "save the data in the form's current record if it's dirty, then go back to the database and get the latest values for all the records displayed by the form."  Your form is unbound, so it has no records to refresh.

The form has a Recalc method, which tells it to recalculate the values of all the calculated controls on the form.  You could call this method from code behind the form by saying "Me.Recalc".  That could be used to force your DLookup() text box to recalculate, but it's overkill.  There's no such method for the text box alone, though.  In this case, telling the text box to Requery itself accomplished what you want in the most efficient way.

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2012-02-06T22:06:20+00:00

Are we talking about the DLookup being in a text box control on a form?  Not sure what else it could be and make sense ...

If it is a form, then Refresh the form only updates the displayed records with any changes made by other users.  This is an unusual thing to do that is rarely useful.

If you want the text box to redo its expression, then you need a line of code in an event in the form:

   Me.[the text box name].Requery

Don't forget that if the reason you need to redo the DLookup is because you changed a value in a field in the form's record source table/query.  Then the changed record needs to be saved before DLookup can see it.  More details about what you are doing when you want to redo the DLookup might allow me to be more specific about exactly what is needed and where it can be done.

Important note:  You should NEVER use SendKeys to get Access to do something.  SendKeys is so fraught with problems that it was removed in A2010.

Was this answer helpful?

0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-02-07T18:01:44+00:00

    Need more specific details.  If you used wizard generated code, it may have used the word "refresh" loosly (like in a browser) and not Access's Refresh method.  Post a Copy/Paste of the code so I can see if we're talking about DoCmd.Refresh or Runcommand. acCmdRefresh which are kind of vague about what they actually do or yhr form Refresh method, which is very specific.

    Regardless of that, requerying a text box is the highly focused way to recalculate a text box expression.  Just for the sake of adding to the confusion, text boxes do not have the Recalc method  ;-)

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-02-07T04:06:59+00:00

    Are we talking about the DLookup being in a text box control on a form?  Not sure what else it could be and make sense ...

    If it is a form, then Refresh the form only updates the displayed records with any changes made by other users.  This is an unusual thing to do that is rarely useful.

    If you want the text box to redo its expression, then you need a line of code in an event in the form:

       Me.[the text box name].Requery

    Don't forget that if the reason you need to redo the DLookup is because you changed a value in a field in the form's record source table/query.  Then the changed record needs to be saved before DLookup can see it.  More details about what you are doing when you want to redo the DLookup might allow me to be more specific about exactly what is needed and where it can be done.

     

    Important note:  You should NEVER use SendKeys to get Access to do something.  SendKeys is so fraught with problems that it was removed in A2010.

    Thanks for the advice.   I'll try the requery  tomorrow.  This is an unbound form that has a combo box that pulls data from a table.  I then have a text box that does a dlookup based off of the combo box's data to help refine a report without making the user have to waste time with this text box.  Why does the dlookup work in my other forms without the requery?  I could just copy the referesh button coding and paste it on the forms current event and the after update event of the combo box. In this form it errors out saying refresh not currently available. This made me confused.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-02-06T21:08:08+00:00

    I got this to work adding a sendkeys "{f5}", true .  Although, can someone please explain why the refresh method doesn't work and I get an error 2046 refresh unavailable error?  I ask this because this never happened in other databases that I created.

    Thanks

    Was this answer helpful?

    0 comments No comments