Solved

MS Access - Form AfterUpdate - Need to reset Focus

Posted on 2009-04-11
7
943 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

691 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