Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 03-17-2018, 05:08 AM   #1
mtagliaferri
Newly Registered User
 
Join Date: Jul 2006
Posts: 495
Thanks: 53
Thanked 0 Times in 0 Posts
mtagliaferri is on a distinguished road
Refresh Another Form On Form Close

I need to refresh a form after I added a new record from a popup form, I am aware of the requery function but I am struggling to put it in place; I believe I should ad a line on save comand which closed the popup form.

the code is:
Code:
Private Sub CmdSave_Click()
    On Error GoTo Err_CmdSave_Click
    DoCmd.Close
Exit_CmdSave_Click:
    Exit Sub
Err_CmdSave_Click:
    MsgBox Err.Description
    Resume Exit_CmdSave_Click

End Sub
Any suggestions?

mtagliaferri is offline   Reply With Quote
Old 03-17-2018, 05:13 AM   #2
Gasman
Access newbie
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 2,293
Thanks: 290
Thanked 349 Times in 334 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: Refresh Another Form On Form Close

How are you calling the popup form?
If from the form that has the new record, you could put it there?
__________________
Access novice. Sometimes trying to give something back.
Access 2007
Gasman is offline   Reply With Quote
Old 03-17-2018, 05:23 AM   #3
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,195
Thanks: 11
Thanked 683 Times in 642 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: Refresh Another Form On Form Close

If you are opening the secondary form in Dialog mode (which halts code execution in the primary, calling Form) all you have to do, after the line that opens the secondary Form, is simply add

Me.Requery

Linq ;0)>

__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
Old 03-17-2018, 05:32 AM   #4
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 11,535
Thanks: 54
Thanked 1,871 Times in 1,821 Posts
jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice
Re: Refresh Another Form On Form Close

I'm not sure why you have the pop up form, but I stumbled upon this technique that might be of interest to you --even if only for reference.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
The Following User Says Thank You to jdraw For This Useful Post:
Gasman (03-17-2018)
Old 03-19-2018, 12:30 AM   #5
Reichel
Newly Registered User
 
Join Date: Nov 2017
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Reichel is on a distinguished road
Re: Refresh Another Form On Form Close

I had a problem in the past with requery or refresh when the focus is on another form than what needs updating ( in this case the pop up)

you can try adding a empty control on main form( call it Z for example), make your pop-up move focus to Z on close. Set Z to requery once it gets focus.

it's probably not the best solution, but it worked for me.
Reichel is offline   Reply With Quote
Old 04-07-2018, 06:05 AM   #6
mtagliaferri
Newly Registered User
 
Join Date: Jul 2006
Posts: 495
Thanks: 53
Thanked 0 Times in 0 Posts
mtagliaferri is on a distinguished road
Re: Refresh Another Form On Form Close

I am afraid it does not open in Dialog
Code:
Private Sub CmdAdd_Click()
    DoCmd.OpenForm "frmDuty", acNormal, "", "", acAdd
    Forms!frmDuty.TripDate.SetFocus
End Sub
mtagliaferri is offline   Reply With Quote
Old 04-07-2018, 06:18 AM   #7
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 11,535
Thanks: 54
Thanked 1,871 Times in 1,821 Posts
jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice
Re: Refresh Another Form On Form Close

see https://msdn.microsoft.com/en-us/vba...-method-access

expression. OpenForm (FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)

and look at windowmode parameter

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
The Following User Says Thank You to jdraw For This Useful Post:
mtagliaferri (04-08-2018)
Old 04-07-2018, 07:13 AM   #8
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,195
Thanks: 11
Thanked 683 Times in 642 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: Refresh Another Form On Form Close

Quote:
Originally Posted by mtagliaferri View Post

I am afraid it does not open in Dialog

Code:
Private Sub CmdAdd_Click()
    DoCmd.OpenForm "frmDuty", acNormal, "", "", acAdd
    Forms!frmDuty.TripDate.SetFocus
End Sub
Not surprising! The correct syntax would not be

DoCmd.OpenForm "frmDuty", acNormal, "", "", acAdd

but

DoCmd.OpenForm "frmDuty", acNormal, "", "", acFormAdd, acDialog

Not trying to be mean, or unkind, but in Access VBA, as in all coding, being 'close' just won't work...you have to be exact.

Linq ;0)>
__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
The Following User Says Thank You to missinglinq For This Useful Post:
mtagliaferri (04-08-2018)
Old 04-08-2018, 06:25 AM   #9
mtagliaferri
Newly Registered User
 
Join Date: Jul 2006
Posts: 495
Thanks: 53
Thanked 0 Times in 0 Posts
mtagliaferri is on a distinguished road
Re: Refresh Another Form On Form Close

Thank for the info!
I have changed the code to your suggestion and added Me.Requery and works perfectly.

Now I have another issue the mail form has the following code to scroll to the last 25 records on the list

Code:
Private Sub Form_Open(Cancel As Integer)
   With Me.Recordset
      .MoveLast
      .Move -25
   End With
End Sub
where should I put the above code to show the last 25 records?
mtagliaferri is offline   Reply With Quote
Old 04-08-2018, 06:36 AM   #10
ridders
Part time moderator
 
ridders's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 6,209
Thanks: 83
Thanked 1,532 Times in 1,427 Posts
ridders is just really nice ridders is just really nice ridders is just really nice ridders is just really nice ridders is just really nice
Re: Refresh Another Form On Form Close

Why not sort in reverse order and select the top 25 in the record source instead so the most recent is at the top?
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

New example databases:

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

-----------------------------------------------------------------------------------
nil illegitimi carborundum est

Last edited by ridders; 04-08-2018 at 11:15 AM.
ridders is offline   Reply With Quote
The Following User Says Thank You to ridders For This Useful Post:
mtagliaferri (04-10-2018)
Old 04-08-2018, 10:52 AM   #11
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,195
Thanks: 11
Thanked 683 Times in 642 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: Refresh Another Form On Form Close

Quote:
Originally Posted by mtagliaferri View Post

I have changed the code to your suggestion and added Me.Requery and works perfectly.

Now I have another issue the mail form has the following code to scroll to the last 25 records on the list...where should I put the above code to show the last 25 records?
Glad that you got that first problem working!

As a rule, the Form_Open event is too early to do anything related to data...that's usually done in the Form_Load event...so you can try the code there, although I'm not sure that your

.Move -25

will do the trick.

I'd try something like this:

Code:
Private Sub Form_Load()

DoCmd.GoToRecord , , acLast

For i = 1 To 24
 DoCmd.GoToRecord , , acPrevious
Next i

End Sub


Linq ;0)>
__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
Old 04-08-2018, 11:31 AM   #12
Gasman
Access newbie
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 2,293
Thanks: 290
Thanked 349 Times in 334 Posts
Gasman has a spectacular aura about Gasman has a spectacular aura about
Re: Refresh Another Form On Form Close

I have this code in one of my forms doing the same thing, but for 5 records.

Code:
    DoCmd.RunCommand acCmdRecordsGoToLast
    DoCmd.GoToRecord acDataForm, Me.Name, acPrevious, 5 ' Needed for a continuous form as only last record shows.
    DoCmd.RunCommand acCmdRecordsGoToLast
HTH
__________________
Access novice. Sometimes trying to give something back.
Access 2007
Gasman is offline   Reply With Quote
The Following User Says Thank You to Gasman For This Useful Post:
mtagliaferri (04-10-2018)
Old 04-10-2018, 09:54 AM   #13
mtagliaferri
Newly Registered User
 
Join Date: Jul 2006
Posts: 495
Thanks: 53
Thanked 0 Times in 0 Posts
mtagliaferri is on a distinguished road
Re: Refresh Another Form On Form Close

Quote:
Originally Posted by missinglinq View Post
Glad that you got that first problem working!

As a rule, the Form_Open event is too early to do anything related to data...that's usually done in the Form_Load event...so you can try the code there, although I'm not sure that your

.Move -25

will do the trick.

I'd try something like this:

Code:
Private Sub Form_Load()

DoCmd.GoToRecord , , acLast

For i = 1 To 24
 DoCmd.GoToRecord , , acPrevious
Next i

End Sub


Linq ;0)>
I have tried this option but not successful, the list form that is included into a tabbed main form stays open in the background as the Add Form opens as pop up, this might be the reason...
Anymore thoughs? I can possible sort them in reverse order but is not really the ideal solution...
mtagliaferri is offline   Reply With Quote
Old 04-11-2018, 11:57 AM   #14
Sweetu
Newly Registered User
 
Join Date: Sep 2016
Posts: 21
Thanks: 14
Thanked 1 Time in 1 Post
Sweetu is on a distinguished road
Re: Refresh Another Form On Form Close

Quote:
Originally Posted by mtagliaferri View Post
I have tried this option but not successful, the list form that is included into a tabbed main form stays open in the background as the Add Form opens as pop up, this might be the reason...
Anymore thoughs? I can possible sort them in reverse order but is not really the ideal solution...
make one combobox & add Ascending & Descending list,
On After update Event paste this code

Code:
If Me.YourComboboxName.Value = "Ascending" Then
    DoCmd.SetOrderBy " Primary kEy or your value for ASC"
Else
    If Me.YourComboboxName.Value = "Descending" Then
    DoCmd.SetOrderBy "Primary kEy or your value for DESC"
End If
End If
then you can refer another box to put the value how many records you want to show & merge that with this ascending & descending code

Sweetu is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Refresh a different form on close AWilderbeast Forms 8 10-18-2014 03:17 PM
[SOLVED] Refresh on form close using VBA gsandy Forms 3 09-18-2014 10:39 AM
Refresh Another Form On Form Close Jamz Macros 5 02-22-2012 05:01 PM
Refresh data in the forms by close other form Kristaline Forms 4 03-31-2009 03:52 PM
Refresh a differnent form on close AWilderbeast Forms 0 05-08-2006 01:38 AM




All times are GMT -8. The time now is 11:08 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World