Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tab Control With a Subform - OnCurrent Running Twice

Status
Not open for further replies.

dftjsn

Programmer
Feb 25, 2002
43
US
On a form, I have a tab control that has two pages (Main and Pictures). The second page contains a subform that displays pictures of the object described on the Main page of the tab control. The problem I'm noticing is that when I view the form or move from record to record the OnCurrent event of the subform on the Picture tab runs runs twice before the OnCurrent event on the primary form fires. So the image gets loaded twice, error messages show twice, etc. When I just cycle through the pictures on the Picture tab, the subform OnCurrent event fires just once as expected, but if I change records on the Main form, the subform OnCurrent event fires twice.

Can anyone explain what is going on and how to fix it?

Thanks!

dftjsn
 
Can't really explain it, but I have seen it before.

I remember once feeling like i needed to use the on current so I did something like set a form-level variable or a tag of some control to 1 when it ran the first time and then only firing the code I wanted to fire if that variable was already 1. Sounds pretty kludgy to me now, but I think it worked, at the time.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access databases since 1995.
 
Jeremy - thanks for the response. I think I figured out what was causing the OnCurrent event to fire twice for the subform contained on the Picture tab of my tab control. Upon closer inspection of the main form containing the tab control, I found I could scroll out to the right off the page. There, out of sight, on what would be in essence the Main tab of the tab control, was a copy of the subform. So, the subform was on both pages/tabs of the control (but I couldn't see it on the Main page/tab because it was out of view) and hence firing the OnCurrent event twice. Not sure how the subform got on the first page/tab of the tab control.

dftjsn
 
Just some things I have noticed over time fighting that same type of situation. There are certain events which will trigger an On Current call. Off the top of my head, here are a few I have encountered:

A) Setting OrderBy to a different value or string

B) Setting AddNewRecords to True

C) Some of the Wizard button code for save, undo, cancel, etc.

D) Changing the record in the recordset behind the form.

If you have time, put your code into single step mode and see what is triggering the On Current event.

By the way, putting OrderBy logic in the Form_Current code will only execute once, but don't ask me why.

Good Luck! Please remember to give helpful posts the stars they deserve! This makes the post more visible to others in need![thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top