Ms Access listbox requery not working

M

Montez659

Well-known Member
JoinedMay 4, 2005Messages918
  • Jul 7, 2011
  • #1
well, I have been toying with this for the last day and I am still having trouble understanding why I am not getting what I want.

I essentially have a list of items that when the listbox is double clicked, opens a bound form to update. When cmdExit is clicked, it should requery the listbox on the other form and display the updated info. However it is not doing that. This is what I have but I cannot figure out what to do differently, and I have been googling all day trying to understand it.
Code:
Private Sub cmdExit_Click() Forms.frmChooseBudgetSub.lstBudgetSub.Requery Forms.frmChooseBudgetSub.Repaint DoCmd.Close acForm, "DEPfrmSettings_BudgetSub", acSaveYes End Sub
Btw, this code is on DEPfrmSettings_BudgetSub, which would close out at the end.

Any help is always appreciated!
Ms Access listbox requery not working

Norie

Well-known Member
JoinedApr 28, 2004Messages76,327Office Version
  1. 365
Platform
  1. Windows
  • Jul 7, 2011
  • #2
Is the form you are trying to requery/refresh open when you try this?
Ms Access listbox requery not working

boblarson

MrExcel MVP
JoinedNov 14, 2008Messages1,964
  • Jul 7, 2011
  • #3
You need to use

Forms!FormNameHere.SubformControlNameHere.Form.controlNameHere.Requery

So the Forms collection uses the BANG (!) not the period. Also, if this code is not on the form where the subform is, you need to refer to the main form first (see FormNameHere above) and then the subform control (control which houses the subform, not the subform name itself unless the subform control and the subform share the same name) and then the .Form. (dot Form dot) which tells Access you want something on the subform and then the control name and then the requery part.

You can omit the dot form dot part if the subform control and the subform are exactly the same name but if they are different you need to use it.
M

Montez659

Well-known Member
JoinedMay 4, 2005Messages918
  • Jul 7, 2011
  • #4
We might be on to something. I did just change that period to the bang before I checked back, but Bob you were talking about subforms and such and that triggered something in my mind. The listbox isn't in a subform, but it is in a tab control, specifically on tabBudget. Would that have something to do with it?

Also, I noticed that as the code exists, it will update if you open the subform twice. It updates the second time, not the first. Thought that was weird 'cause it's looping through the same code.

And yes, the form is open.
M

Montez659

Well-known Member
JoinedMay 4, 2005Messages918
  • Jul 7, 2011
  • #5

ADVERTISEMENT

Dang, I take that back...I was confused for a moment. It isn't on a separate tab, and it might be in a subform. Lemme check...

Ok, it is on a separate tab, not in a subform.
Last edited: Jul 7, 2011
Ms Access listbox requery not working

boblarson

MrExcel MVP
JoinedNov 14, 2008Messages1,964
  • Jul 7, 2011
  • #6
okay, so it would simply be:

Forms!frmChooseBudgetSub.lstBudgetSub.Requery

But also are you aware that the acSaveYes that you are using in the DoCmd.Close code means that DESIGN CHANGES to the form are to be saved (it has nothing to do with records)? That is not a good idea. You should use acSaveNo as you don't want to end up with persistent filters and such and then if you end up making an MDE or ACCDE file then this would fail with an error because design changes cannot be saved by them.
M

Montez659

Well-known Member
JoinedMay 4, 2005Messages918
  • Jul 7, 2011
  • #7

ADVERTISEMENT

boblarson said:
okay, so it would simply be:

Forms!frmChooseBudgetSub.lstBudgetSub.Requery
Click to expand...

See, I knew I wasn't crazy! I tried that a million (slight exageration) times but I am still only getting it to requery every other time.

Ahhhh, I bet I know what is happening! I bet after the exit button is clicked the first two lines of code are running, but the form is still dirty until the DoCmd.Close is running. So the requery is working but triggering before the record is updated.
Ms Access listbox requery not working

boblarson

MrExcel MVP
JoinedNov 14, 2008Messages1,964
  • Jul 7, 2011
  • #8
Montez659 said:
See, I knew I wasn't crazy! I tried that a million (slight exageration) times but I am still only getting it to requery every other time.

Ahhhh, I bet I know what is happening! I bet after the exit button is clicked the first two lines of code are running, but the form is still dirty until the DoCmd.Close is running. So the requery is working but triggering before the record is updated.
Click to expand...

If you want to save first, just put this:

If Me.Dirty Then Me.Dirty = False

just before the requery.
M

Montez659

Well-known Member
JoinedMay 4, 2005Messages918
  • Jul 7, 2011
  • #9
There it is!
Code:
Me.Dirty = False Forms!frmChooseBudgetSub.lstBudgetSub.Requery Forms!frmChooseBudgetSub.Repaint DoCmd.Close acForm, "DEPfrmSettings_BudgetSub", acSaveNo

Thanks!