Solved

MS Access - Form AfterUpdate - Need to reset Focus

Posted on 2009-04-11
7
936 Views
Last Modified: 2013-11-28
Hi-
I added column Updated_Date to my Company table.

On the AfterUpdate section of my form CompanyMain, I have this:
private sub form_afterupdate()
    Me.Updated_Date = Now()
end sub

But although it does time-stamp it doesn't give me focus back to work on another part of the form....
Any ideas?
Stacy
0
Comment
Question by:stacydr
  • 3
  • 3
7 Comments
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24124659
It sounds like you just need to add a line of code to manually set the focus wherever you need it.  But that's pretty obvious so I'm thinking that's probably not your problem.
0
 
LVL 2

Author Comment

by:stacydr
ID: 24127964
Hi-
I guess the problem is I'm not sure where the focus from the user will be next.
The Main Form is Company Main
within is three subforms:
CompanyDetail
ContactsDetail
ActivityMain (Which has it's own subreport ActivityDetail)
So a user could potentially go anywhere within the 5 noted forms..

right now: It's like the whole form just stops working...

I tried to add Me.SetFocus to the noted code but that didn't work.
So here I am..
Sorry I'm not better at this - I haven't used Access like this is a number of years and I keep confusing my languages, I probably shouldn't have started this project but here I am..
so thanks for any time your spending on helping me..Stacy
0
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24133375
OK, problems like these are 'usually' best solved by using an implementation that isn't dependent on focus.  If I knew exactly what you were trying to do maybe I could help with that.

When you are working with multiple forms each form has its own focus, but only one form is active at a time and you can programmatically activate a different form if you need to.  I don't remember exactly how this works with subforms because I haven't worked with subforms or Access in a long time, but if your setfocus statement isn't working then perhaps it's because the wrong form is currently active.  

Also, don't forget that code in a subform can access the parent form.  Of course, you will have to be careful about doing this if the subform is used in other forms.

If none of that helped or lead you in the right direction then post a little bit more detail on the big picture of what you're trying to do.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Author Comment

by:stacydr
ID: 24134036
Hi -
Thanks for helping..
What I'm trying to do is if a Company or Contact is updated, then I want to timestamp the Update_Date field.  But when I add this function in -- I can't move to another company or subform after I update the record.  And when I try to close the form -- I get an error that says I can't save the record at this time (even though it already timestamped the row)..
Stacy
0
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24134644
Is that all the error says or does it give any more detail as to why it can't close the form?

Have you tried programatically saving the record right after you add the timestamp?  Try doing this and if it still give you an error let me know what it is.

You might also try updating the table directly (ie. the way you would if it wasn't connected to the Recordset property and you couldn't use the "Me" keyword to access it).  If you do this and it works, you may have to call some function to refresh the screen so that the timestamp will show up on screen after you add it.
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 24135435
Stacy, Ive been thinking about this, I think it has to do with the time, seconds part that changed and so form changes again, it might be in a loop. Ive used things to update in the afterupdate event and not had a problem, mind you, I dont recall using time

Can you try this out on the beforeupdate event

private sub form_beforeupdate(cancel as integer)
    Me.Updated_Date = Now()
end sub

If you want it to update on specific field changes only then use the beforeupdate (or afterupdate) event of that individual control only and not the form level event.

This should still set your date
0
 
LVL 2

Author Closing Comment

by:stacydr
ID: 31569276
Thanks that seemed to do it!
Stacy
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now