M Montez659Well-known MemberJoinedMay 4, 2005Messages918
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 Any help is always appreciated! NorieWell-known MemberJoinedApr 28, 2004Messages76,327Office Version
Is the form you are trying to requery/refresh open when you try this? boblarsonMrExcel MVPJoinedNov 14, 2008Messages1,964
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 Montez659Well-known MemberJoinedMay 4, 2005Messages918
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 Montez659Well-known MemberJoinedMay 4, 2005Messages918
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 boblarsonMrExcel MVPJoinedNov 14, 2008Messages1,964
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 Montez659Well-known MemberJoinedMay 4, 2005Messages918
ADVERTISEMENT
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. boblarsonMrExcel MVPJoinedNov 14, 2008Messages1,964
If you want to save first, just put this: If Me.Dirty Then Me.Dirty = False just before the requery. M Montez659Well-known MemberJoinedMay 4, 2005Messages918
There it is! Code: Me.Dirty = False
Forms!frmChooseBudgetSub.lstBudgetSub.Requery
Forms!frmChooseBudgetSub.Repaint
DoCmd.Close acForm, "DEPfrmSettings_BudgetSub", acSaveNo Thanks! |