Unanswered: Edit link in data sheet to open new form - how do I know when it is done?
I have a data sheet in which I have set up an "edit" link that allows me to open up a form to edit the record. The form is opened with DoCmd.OpenForm.
Originally I was executing OpenForm with the acWindowDialog parameter which pops open the form in dialog mode and freezes the calling code. When the form closed, I could then refresh the data sheet to capture any changes.
Recently I decided that I did NOT want to use dialog mode, I wanted to open the new form using acWindowNormal in order to take advantage of the tabbed interface that I'm using for the database. I also do NOT want to open the form as modal, since I want the user to be able to access other parts of the database.
Opening up the form with acWindowNormal does not freeze the calling code. I therefore need a method of notifying the datasheet when the form closes so it knows to update it self.
Any suggestions on how best to approach this?
I've been looking at an event callback mechanism suggsted by someone in a separate thread, but I'm wondering if there is a better way of handling this. The callback mechanism seems to breakdown when the datasheet is a subform or a subform to a subform.
I'm not sure if I completely understand what you are attempting to do. However, if all you are wanting to do is to update your datasheet directly from a form I would use a button. You are already having to close the form, so put a close button on it. On the event click have it update the record and close the form. The datasheet should automatically be updated with the new information. Simple vba code for updating a record from a form is:
If Me.Dirty Then Me.Dirty = False
That's the easiest way I know how to do it without messing with form events.
I have a datasheet (used as a subform) that includes a subset of columns from Table A. In each datasheet line I have created an "Edit" link which opens up a form that allows me to edit all of the columns (as defined in Table A) for that particular record . The form has a nice "Save" button that I hit, which saves the record, and closes the form.
However this does NOT update the datasheet from which I originally called the form. I can wait long enough and Access' automatic refresh may kick in, but as a general rule a refresh must be forced. The problem from the data sheet's perspective is that I don't know when the edit form closed so I can issue a refresh.
I cannot say I use datasheets much. However, they should act just like any other form. What your looking for is the On Activate event on your datasheet form.
This event will fire when you close the popup form and your datasheet becomes your active form. you can do a docmd runcommand accmdrefreshpage (it will not let me put the . between docmd and the other part, bleh still new to using the forum) in that event and it should take care of your problem. If it acts like a regular form.
I thought about putting the refresh in OnActivate or OnFocus however - that will force a refresh of the datasheet whenever the user happens to move some place else - regardless of whether the data has been changed or not. Do to a slow link to the back end, I would prefer to only refresh when I need to.
Then outside of manually refreshing it I only have one other idea and its not a pretty one but it will work. On your save button on the edit form, you can use the docmd.close on your datasheet then open it again then close the edit form.
Same case little different on your form have a close button. Save closes the datasheet, then you hit the close button to close the edit form and open the datasheet. Again if you want it to be automated that is the only solution I'm aware of. Sorry that I don't have a better answer for you, but not using the On activate event hurts the options.
I know this is a bit late, but I was working on one of my databases and I remember this. It might help you out. You can force a refresh on a different form/control with the click event from your update form.
Don't know why I hadn't thought of that earlier. So put that on the click event of the button that closes down your update form. See if that helps!