Requery Not Working

S

sandpking

From the main menu, I have a Max query that displays the most recent
date of a particular field. When I go into a form off of the main
menu and update that field, I'd like the main menu to be updated. The
code below does not work. Any help is appreciated.
Private Sub Command15_Click()
Dim frm As Form

On Error GoTo Err_CloseImportForm_Click

If CurrentProject.AllForms("Frm_Main_Menu").IsLoaded Then
Set frm = Forms![Frm_Main_Menu]
frm.Requery
frm.Refresh
Set frm = Nothing
End If
If Me.Dirty Then Me.Dirty = False

DoCmd.Close

Exit_CloseImportForm_Click:
Exit Sub

Err_CloseImportForm_Click:
MsgBox Err.Description
Resume Exit_CloseImportForm_Click



End Sub
 
K

Klatuu

The Requery is working. You have your order of actions upside down. You
need to save the record before you requery the form. The refresh is
unnecessary. Try this version:

On Error GoTo Err_CloseImportForm_Click

If Me.Dirty Then
Me.Dirty = False
If CurrentProject.AllForms("Frm_Main_Menu").IsLoaded Then
Forms![Frm_Main_Menu].Requery
End If
End If

DoCmd.Close acForm, Me.Name, acSaveNo

This will only requery the form If the record was added to the table.
 
S

sandpking

That closed the main menu too. I wanted the main menu to stay open,
but have a field on it update.
The Requery is working.  You have your order of actions upside down.  You
need to save the record before you requery the form.  The refresh is
unnecessary.  Try this version:

    On Error GoTo Err_CloseImportForm_Click

    If Me.Dirty Then
        Me.Dirty = False
        If CurrentProject.AllForms("Frm_Main_Menu").IsLoaded Then
            Forms![Frm_Main_Menu].Requery
        End If
    End If

    DoCmd.Close acForm, Me.Name, acSaveNo

This will only requery the form If the record was added to the table.

--
Dave Hargis, Microsoft Access MVP



From the main menu, I have a Max query that displays the most recent
date of a particular field.  When I go into a form off of the main
menu and update that field, I'd like the main menu to be updated.  The
code below does not work.  Any help is appreciated.
Private Sub Command15_Click()
Dim frm As Form
On Error GoTo Err_CloseImportForm_Click
If CurrentProject.AllForms("Frm_Main_Menu").IsLoaded Then
    Set frm = Forms![Frm_Main_Menu]
    frm.Requery
    frm.Refresh
    Set frm = Nothing
End If
If Me.Dirty Then Me.Dirty = False
DoCmd.Close

Exit_CloseImportForm_Click:
    Exit Sub
Err_CloseImportForm_Click:
    MsgBox Err.Description
    Resume Exit_CloseImportForm_Click
End Sub- Hide quoted text -

- Show quoted text -
 
S

sandpking

My fault. I left an extra close in there. Thank you.
That closed the main menu too.  I wanted the main menu to stay open,
but have a field on it update.
The Requery is working.  You have your order of actions upside down.  You
need to save the record before you requery the form.  The refresh is
unnecessary.  Try this version:
    On Error GoTo Err_CloseImportForm_Click
    If Me.Dirty Then
        Me.Dirty = False
        If CurrentProject.AllForms("Frm_Main_Menu").IsLoaded Then
            Forms![Frm_Main_Menu].Requery
        End If
    End If
    DoCmd.Close acForm, Me.Name, acSaveNo
This will only requery the form If the record was added to the table.
From the main menu, I have a Max query that displays the most recent
date of a particular field.  When I go into a form off of the main
menu and update that field, I'd like the main menu to be updated.  The
code below does not work.  Any help is appreciated.
Private Sub Command15_Click()
Dim frm As Form
On Error GoTo Err_CloseImportForm_Click
If CurrentProject.AllForms("Frm_Main_Menu").IsLoaded Then
    Set frm = Forms![Frm_Main_Menu]
    frm.Requery
    frm.Refresh
    Set frm = Nothing
End If
If Me.Dirty Then Me.Dirty = False
DoCmd.Close
Exit_CloseImportForm_Click:
    Exit Sub
Err_CloseImportForm_Click:
    MsgBox Err.Description
    Resume Exit_CloseImportForm_Click
End Sub- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
K

Klatuu

Then change me.name to the name of the form you want to close.
--
Dave Hargis, Microsoft Access MVP


That closed the main menu too. I wanted the main menu to stay open,
but have a field on it update.
The Requery is working. You have your order of actions upside down. You
need to save the record before you requery the form. The refresh is
unnecessary. Try this version:

On Error GoTo Err_CloseImportForm_Click

If Me.Dirty Then
Me.Dirty = False
If CurrentProject.AllForms("Frm_Main_Menu").IsLoaded Then
Forms![Frm_Main_Menu].Requery
End If
End If

DoCmd.Close acForm, Me.Name, acSaveNo

This will only requery the form If the record was added to the table.

--
Dave Hargis, Microsoft Access MVP



From the main menu, I have a Max query that displays the most recent
date of a particular field. When I go into a form off of the main
menu and update that field, I'd like the main menu to be updated. The
code below does not work. Any help is appreciated.
Private Sub Command15_Click()
Dim frm As Form
On Error GoTo Err_CloseImportForm_Click
If CurrentProject.AllForms("Frm_Main_Menu").IsLoaded Then
Set frm = Forms![Frm_Main_Menu]
frm.Requery
frm.Refresh
Set frm = Nothing
End If
If Me.Dirty Then Me.Dirty = False
DoCmd.Close

Exit_CloseImportForm_Click:
Exit Sub
Err_CloseImportForm_Click:
MsgBox Err.Description
Resume Exit_CloseImportForm_Click
End Sub- Hide quoted text -

- Show quoted text -
 

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