OnCurrent not triggered by return from another form

L

larry.nolan

I'm debugging a Access97 d.b. that has been converted to Access 2002.
From form "Vol Info" I have a button that takes me to Form B. When I
return from Form B, I have this code that is executed when I click on
the "Return" button:

Private Sub ReturnButton_Click()
DoCmd.Close , ""
DoCmd.OpenForm "Vol Info", acNormal, "", "", acEdit, acNormal
DoCmd.RunCommand acCmdRefresh
End Sub

the "Vol Info" form has a OnCurrent property to execute a procedure
Form_Current() but it is not executed when I return from Form B via the
ReturnButton_Click. The Form_Current() is executed when I click on one
of the navigation buttons to go to the next or previous record in my
bound "Vol Info" form.

Why isn't the OnCurrent event being triggered when I go through the
ReturnButton_Click() routine?
thanks,
Larry
 
D

Dirk Goldgar

I'm debugging a Access97 d.b. that has been converted to Access 2002.

return from Form B, I have this code that is executed when I click on
the "Return" button:

Private Sub ReturnButton_Click()
DoCmd.Close , ""
DoCmd.OpenForm "Vol Info", acNormal, "", "", acEdit, acNormal
DoCmd.RunCommand acCmdRefresh
End Sub

the "Vol Info" form has a OnCurrent property to execute a procedure
Form_Current() but it is not executed when I return from Form B via
the ReturnButton_Click. The Form_Current() is executed when I click
on one of the navigation buttons to go to the next or previous record
in my bound "Vol Info" form.

Why isn't the OnCurrent event being triggered when I go through the
ReturnButton_Click() routine?

I can't think of any reason why it should be. I gather that the form is
still open -- you didn't close it when you opened Form B -- so all
'DoCmd.OpenForm "Vol Info"' is doing is activating it. When you refresh
its records using 'DoCmd.RunCommand acCmdRefresh', you don't cause the
form to move to a new record. So the form has not navigated to a new
record, and therefore there is no reason for its Current event to fire.

I don't think this behavior was any different in Access 97, but I'd have
to test to make sure.
 
L

larry.nolan

I thought doing a acCmdRefresh caused a Current event. It could be an
old bug in the Access 97 code (which I didn't write).
I've determined that if I do this:

Private Sub ReturnButton_Click()
DoCmd.Close , ""
DoCmd.OpenForm "Vol Info", acNormal, "", "", acEdit, acNormal
DoCmd.RunCommand acCmdRefresh
'next two calls are to correct the On Current problem in "Vol Info"
DoCmd.RunCommand acCmdRecordsGoToNext
DoCmd.RunCommand acCmdRecordsGoToPrevious
End Sub

then when I see the Vol Info form again everything is updated to show
the changes that were made when I entered data in the Form B form.

Is there a better way to make sure my Vol Info form gets updated
properly when I return?
Larry
 
L

larry.nolan

This text from the Access 2002 help system is what led me to think the
acCmdRefresh would trigger the Current event for the form:

"Current Event
The Current event occurs when the focus moves to a record, making it
the current record, or when the form is refreshed or requeried."
 
D

Dirk Goldgar

I thought doing a acCmdRefresh caused a Current event. It could be an
old bug in the Access 97 code (which I didn't write).
I've determined that if I do this:

Private Sub ReturnButton_Click()
DoCmd.Close , ""
DoCmd.OpenForm "Vol Info", acNormal, "", "", acEdit, acNormal
DoCmd.RunCommand acCmdRefresh
'next two calls are to correct the On Current problem in "Vol Info"
DoCmd.RunCommand acCmdRecordsGoToNext
DoCmd.RunCommand acCmdRecordsGoToPrevious
End Sub

then when I see the Vol Info form again everything is updated to show
the changes that were made when I entered data in the Form B form.

Is there a better way to make sure my Vol Info form gets updated
properly when I return?

That depends on what your Vol Info form is doing, and what is happening
in the form's Current event. You could requery the form instead of
refreshing it; that would force the Current event to fire, at the cost
of moving the form to the first record in its recordset. Or you could
move the relevant code from the Current event into a Public Sub (still
in the form's module), and call that sub from your ReturnButton's Click
event procedure. Or you could move that code to the form's Activate
event, so that whenever the form becomes active again, the code would
execute.
 
D

Dirk Goldgar

This text from the Access 2002 help system is what led me to think the
acCmdRefresh would trigger the Current event for the form:

"Current Event
The Current event occurs when the focus moves to a record, making it
the current record, or when the form is refreshed or requeried."

The help entry is demonstrably incorrect. I just tested it in both
Access 2002 and in Access 97, and the form's Current event doesn't fire
when the form is refreshed. Requerying will do it.
 
L

larry.nolan

Dirk,
thanks for all the suggestions of alternatives to my GoToNext,
GoToPrevious hack. I'll investigate them further. So much for relying
upon MS Help information!

larry
 
L

larry.nolan

Dirk,
two hopefully simple questions:
1)I'm trying to put a call (in my Return procedure) to a clone of the
Form_Current procedure within the Vol Info form. What's the correct
syntax to call a routine that's in another form? I declared the clone
to be Public and changed it's name from the existing Form_Current
procedure.

2)How do you do a requery and which form would I put it? In the Return
procedure ?

thanks,
Larry
 
L

larry.nolan

Dirk,
cancel that.... I took your suggestion and cloned the Form_Current and
figured out how to call it from the other form's ReturnButton_Click.
That does the trick and I think it's cleaner than my hack using
GoToNext/GotoPrevious.

Appreciate your help as will my users of this converted application.

Larry
 
D

Dirk Goldgar

Larry wrote in message
Dirk,
cancel that.... I took your suggestion and cloned the Form_Current
and figured out how to call it from the other form's
ReturnButton_Click. That does the trick and I think it's cleaner than
my hack using GoToNext/GotoPrevious.

Very good.
Appreciate your help as will my users of this converted application.

I'm glad I could help.
 
J

JIM WHITAKER

use on activate
I'm debugging a Access97 d.b. that has been converted to Access 2002.

return from Form B, I have this code that is executed when I click on
the "Return" button:

Private Sub ReturnButton_Click()
DoCmd.Close , ""
DoCmd.OpenForm "Vol Info", acNormal, "", "", acEdit, acNormal
DoCmd.RunCommand acCmdRefresh
End Sub

the "Vol Info" form has a OnCurrent property to execute a procedure
Form_Current() but it is not executed when I return from Form B via the
ReturnButton_Click. The Form_Current() is executed when I click on one
of the navigation buttons to go to the next or previous record in my
bound "Vol Info" form.

Why isn't the OnCurrent event being triggered when I go through the
ReturnButton_Click() routine?
thanks,
Larry
 
J

JIM WHITAKER

use on activate
I'm debugging a Access97 d.b. that has been converted to Access 2002.

return from Form B, I have this code that is executed when I click on
the "Return" button:

Private Sub ReturnButton_Click()
DoCmd.Close , ""
DoCmd.OpenForm "Vol Info", acNormal, "", "", acEdit, acNormal
DoCmd.RunCommand acCmdRefresh
End Sub

the "Vol Info" form has a OnCurrent property to execute a procedure
Form_Current() but it is not executed when I return from Form B via the
ReturnButton_Click. The Form_Current() is executed when I click on one
of the navigation buttons to go to the next or previous record in my
bound "Vol Info" form.

Why isn't the OnCurrent event being triggered when I go through the
ReturnButton_Click() routine?
thanks,
Larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top