Refresh a different form on close

AWilderbeast

Registered User.
Local time
Today, 16:09
Joined
Sep 13, 2005
Messages
92
HI basically i have a form which dislays records in a continous list, then an add button which adds records to the list. to view the newly added records you have to close the form and open it again.

I have inserted a refresh button but what im after instead is when i close the 'add form' it refreshes the list form. Below is the code for the refresh button could someone tell me what i need to add/change to make it refresh a particular form on close?

Private Sub Command45_Click()
On Error GoTo Err_Command45_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Command45_Click:
Exit Sub

Err_Command45_Click:
MsgBox Err.Description
Resume Exit_Command45_Click

End Sub

Thanks for any help
 
I would start by learning the replacements for the old DoMenuItem code generated by the wizards. Here's a link to help in that task: Converting DoMenuItem to RunCommand Next, the Refresh of a recordset does not pick up new records. You need to Requery the recordset instead. If your first form is still open, I would open the "add form" as acDialog, which will halt the code in the first form, and make the next line after the DoCmd.OpenForm in the first form a Me.Requery, which will pick up any new records after you close the "add form".
 
Thanks... i think.

I dont understand any of what you just said lol.
i think ill just leave it as a button for now
 
Sorry! I didn't mean to loose you. What code are you using to open the "add form"?
 
Private Sub Command41_Click()
On Error GoTo Err_Command41_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "AddVacancy"

stLinkCriteria = "[cu_id]=" & Me![cu_id]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command41_Click:
Exit Sub

Err_Command41_Click:
MsgBox Err.Description
Resume Exit_Command41_Click

End Sub

I Just use the button wizard and everything works fine. All i need is when the add form is closed it refreshes my subform to show the new record just added
 
If this button is on the SubForm then:
Code:
Private Sub Command41_Click()
On Error GoTo Err_Command41_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "AddVacancy"

stLinkCriteria = "[cu_id]=" & Me![cu_id]
DoCmd.OpenForm stDocName, , , stLinkCriteria[b], , acDialog
[COLOR="Red"]Me.Requery[/COLOR][/b] 

Exit_Command41_Click:
Exit Sub

Err_Command41_Click:
MsgBox Err.Description
Resume Exit_Command41_Click

End Sub
If the button is on the MainForm then you will have to replace the Me.Requery with
Me.SubFormControlName.Form.Requery using your SubFormControlName of course.
 
I would start by learning the replacements for the old DoMenuItem code generated by the wizards. Here's a link to help in that task: Converting DoMenuItem to RunCommand Next, the Refresh of a recordset does not pick up new records. You need to Requery the recordset instead. If your first form is still open, I would open the "add form" as acDialog, which will halt the code in the first form, and make the next line after the DoCmd.OpenForm in the first form a Me.Requery, which will pick up any new records after you close the "add form".

thanks a lot it really help


Private Sub cmdaddpatient_Click()

DoCmd.OpenForm "ADD_EditPatient", , , , , acDialog
Me.Requery

End Sub
 
Wouldn't the Requery code be on the "On Close() event of the AddVacancyform? or am I missing something.

No this will be in the click event in the main form to open the other add or edit form as a dialog then wait till it close to make requery

Regards
 

Users who are viewing this thread

Back
Top Bottom