trouble with requery

L

lackeysc

I have a very simple form with a very simple problem but my very
simple mind doesn't seem to be capable of coming up with the very
simple solution. The on click event runs an append query and then a
delete query which are both working fine. I then requery the form but
the records are not going away. Instead, the fields all say deleted in
them. Thanks in advance for your help.

Here is the very simple code:

Private Sub btnExport_Click()
DoCmd.SetWarnings False
On Error GoTo Err_btnExport_Click

Dim stDocName As String

stDocName = "qryAppendToMaster"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.OpenQuery "qryDeleteFromReview", acViewNormal, acEdit

Exit_btnExport_Click:
Exit Sub

Err_btnExport_Click:
MsgBox Err.Description
Resume Exit_btnExport_Click



DoCmd.SetWarnings True
Me.Requery


End Sub
 
L

lackeysc

One clarification. The records obviously do get deleted from the
table. This is a continuous form which continues to show all the lines
where the records were. I would like for the form to only show the new
record line when finished.
 
M

Marshall Barton

I have a very simple form with a very simple problem but my very
simple mind doesn't seem to be capable of coming up with the very
simple solution. The on click event runs an append query and then a
delete query which are both working fine. I then requery the form but
the records are not going away. Instead, the fields all say deleted in
them. Thanks in advance for your help.

Here is the very simple code:

Private Sub btnExport_Click()
DoCmd.SetWarnings False
On Error GoTo Err_btnExport_Click

Dim stDocName As String

stDocName = "qryAppendToMaster"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.OpenQuery "qryDeleteFromReview", acViewNormal, acEdit

Exit_btnExport_Click:
Exit Sub

Err_btnExport_Click:
MsgBox Err.Description
Resume Exit_btnExport_Click



DoCmd.SetWarnings True
Me.Requery


End Sub


First, your error handling code is in the wrong place. It
needs to be at the end of the procedure. The Requery should
be before the Exit Sub

I think your issue is (or will be after moving the Requery)
that OpenQuery runs asynchronously from your code. When you
need the actions to complete before the next line of code,
use the Execute method:

Private Sub btnExport_Click()
Dim db As Database
On Error GoTo Err_btnExport_Click
Set db = CurrentDb()

db.Execute "qryAppendToMaster", dbFailOnError
db.Execute "qryDeleteFromReview", dbFailOnError
Me.Requery

Exit_btnExport_Click:
Exit Sub

Err_btnExport_Click:
MsgBox Err.Description
Resume Exit_btnExport_Click
End Sub
 

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