Requery Question

Lamb2087

Registered User.
Local time
Today, 04:24
Joined
Feb 7, 2003
Messages
103
I have a command button that performs an update query on a table in a subform. When you click the command button and check the table that is being deleted, it works just fine. The subform still shows the data in it that was deleted in the query. Is there a way to refresh the form to show that the table is empty??
 
Me.SubformControlName.Requery or Me.SubformControlName.Refresh. Not sure where your code is running from so the syntax may not be correct. If you are running your code for the main form then change the code to Me.SubformControlName.Form.Refresh

hth,
Jack
 
Jack:
The mainform name: XXXXX
The subform name: TrialCadetAdd
Mainform control commandbutton name:cmdDeleteCadets

The command button is located in the main form and performs the update query on the subform.

Here is the code I have for the command button:

Private Sub cmdDeleteCadets_Click()
Dim MsgResult As Variant
On Error GoTo Err_cmdDeleteCadets_Click
MsgResult = MsgBox("Are you sure you want to delete all the cadets now?", vbYesNo)

If MsgResult = vbYes Then
Dim stDocName As String
stDocName = "DeleteCadetIdQuery"
DoCmd.OpenQuery stDocName, acNormal, acEdit

End If

Exit_cmdDeleteCadets_Click:
Exit Sub

Err_cmdDeleteCadets_Click:
MsgBox Err.Description
Resume Exit_cmdDeleteCadets_Click
 
End If

Me.TrialCadetAdd.Form.Refresh

Exit_cmdDeleteCadets_Click:
Exit Sub

Be sure that TrialCadetAdd is the name of the subform control on the form and not the name of the subform itself. You can also try Me.TrialCadedAdd.Form.Requery if the refresh doesn't do the trick.

hth,
Jack
 
Control Name

Jack:

There is no control in the subform that performs a update query!
The control is located on the main form.
The control that performs the update query is named: cmdDeleteCadets

Here is the code. Based on what I have said above can you tell me the location of the code?

Private Sub cmdDeleteCadets_Click()
Dim MsgResult As Variant
On Error GoTo Err_cmdDeleteCadets_Click
MsgResult = MsgBox("Are you sure you want to delete all the cadets now?", vbYesNo)

If MsgResult = vbYes Then
Dim stDocName As String
stDocName = "DeleteCadetIdQuery"
DoCmd.OpenQuery stDocName, acNormal, acEdit

End If

Exit_cmdDeleteCadets_Click:
Exit Sub

Err_cmdDeleteCadets_Click:
MsgBox Err.Description
Resume Exit_cmdDeleteCadets_Click

End Sub
 
Did you try my previous post? I put the code where it should go in your code, right after the 'End If' and before the 'Exit_cmdDeleteCadets_Click:'

A subform is a control on a main form and that is why I mentioned that you be sure the code refers to the subform control and not the name of the subform. A subform can be named 'sfrmMySubform' but the subform control can be named 'MySubform'. Refering to 'sfrmMySubform' in the code will not work.

Jack
 

Users who are viewing this thread

Back
Top Bottom