Link to home
Start Free TrialLog in
Avatar of stacydr
stacydrFlag for United States of America

asked on

MS Access - Form AfterUpdate - Need to reset Focus

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
Avatar of brandonvmoore
brandonvmoore

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.
Avatar of stacydr

ASKER

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
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.
Avatar of stacydr

ASKER

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
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.
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stacydr

ASKER

Thanks that seemed to do it!
Stacy