How to refresh a table after updating the main form from popup form?

  • Thread starter forcefield via AccessMonster.com
  • Start date
F

forcefield via AccessMonster.com

Hi Everyone
My popup form, frmPop can update my main form, frmMain, but the table
remains unchanged ( or unrefreshed). How do you refresh the table?

Main table
tblMain

frmMain -- main form.
txtStandbyCash -- text field
txtPettyCash -- text field

frmPop -- popup form
cboXtraCash -- combo
cmdUpdate -- update button
cmdCancel -- Cancel button

While both frmMain and frmPop remain opened, clicking the update button on
frmPop will effect the following
1. txtStandbyCash to add to txtPettyCash
2. txtStandbyCash is being replaced by the value of cboXtraCash
3. frmPop closes leaving the main form, frmMain still opened.
Since frmMain draws its data from tblMain I expect the tblMain to be
refreshed,
but it did not. I have tried DoCmd.Requery in the update button but it does
not
work. How do I get the tblMain refreshed and where do I place such code?

The code for the update button:

Select Case MsgBox("Are you sure you want to add your yearly entitlement?", _
vbYesNo + vbExclaimation + vbSystemModal + vbDefaultButton1)

Case vbYes
[Forms]![frmMain].txtPettyCash = [Forms]![frmMain].
txtPettyCash +_
[Forms]![frmMain].txtStandbyCash
[Forms]![frmMain].txtStandbyCash = _
[Forms]![frmPop].cboXtraCash

Case vbNo
‘ Do nothing

End Select

DoCmd.Close acForm, "frmPop", acSaveYes

Thanks
 
M

Marshall Barton

forcefield said:
My popup form, frmPop can update my main form, frmMain, but the table
remains unchanged ( or unrefreshed). How do you refresh the table?

Main table
tblMain

frmMain -- main form.
txtStandbyCash -- text field
txtPettyCash -- text field

frmPop -- popup form
cboXtraCash -- combo
cmdUpdate -- update button
cmdCancel -- Cancel button

While both frmMain and frmPop remain opened, clicking the update button on
frmPop will effect the following
1. txtStandbyCash to add to txtPettyCash
2. txtStandbyCash is being replaced by the value of cboXtraCash
3. frmPop closes leaving the main form, frmMain still opened.
Since frmMain draws its data from tblMain I expect the tblMain to be
refreshed,
but it did not. I have tried DoCmd.Requery in the update button but it does
not
work. How do I get the tblMain refreshed and where do I place such code?

The code for the update button:

Select Case MsgBox("Are you sure you want to add your yearly entitlement?", _
vbYesNo + vbExclaimation + vbSystemModal + vbDefaultButton1)

Case vbYes
[Forms]![frmMain].txtPettyCash = [Forms]![frmMain].
txtPettyCash +_
[Forms]![frmMain].txtStandbyCash
[Forms]![frmMain].txtStandbyCash = _
[Forms]![frmPop].cboXtraCash

Case vbNo
‘ Do nothing

End Select

DoCmd.Close acForm, "frmPop", acSaveYes


The table data will not be updated until the record in
frmMain is saved. This will happen automatically if you
navigate to a different record in frmMain, navigate to a
subform on frmMain or (as long as there are no validation
errors) when frmMain is closed. In general, you should not
be concerned with this unless you are doing something else
at this point in time that requires the record be saved
prematurely

There should be no need to Requery anything since the bound
controls on frmMain have already been set.

Note that you are saving frmPop's **design** in your use of
the Close method. This is a bad thing to do in all but a
few very special situations.

Try using code more like:

Select Case MsgBox(" . . .
Case vbYes
With Forms!frmMain
.txtPettyCash = .txtPettyCash +.txtStandbyCash
.txtStandbyCash = Me.cboXtraCash
' if required, save record
.Dirty = False
End With
Case vbNo
‘ Do nothing
End Select

DoCmd.Close acForm, "frmPop", acSaveNo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top