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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a continuous form on a tab control to a new record 1

Status
Not open for further replies.

Eutychus

Programmer
Nov 14, 2007
61
US
Access 2013. I have a form (frmMaintenance) with a tab control (TabCt10) and each page on the tab control has a form (subform) on it. The data on each subform is independent of the frmMaintenance (no Master-child relationship) and has its own query with its own table behind it. For two days I've been trying to get the forms on each page of the tab control to open to a new record. The forms are continuous forms. So, when I open frmMaintenance, I want the initial tab (Cars) to open the form (say, frmCars) to a new record. If I click on the next tab (Trucks), I want the page to open to a new record on the frmTrucks. Likewise, when I click the tab Motorcycles, I want the frmMotorcycles on that page of the tab control to open to a new record. Currently, the subforms open to the first record.

When I try to set the form's OnOpen event to go to a new record on the form, I get an error saying the form is not open. Same with OnCurrent event. I've tried using the OnClick event for each page and that doesn't work. I've googled and tried many other things too numerous to list here, none of which can I get to work.

I'm stumped. Can anyone tell me with some detail how to do this? I don't mean to be impertinent, but I would appreciate a real working solution, not just a guess that something "should work."

Thank you very much!

 
What version of Access are you using?
I have an event in the OnClick for a tab on a form. It doesn't have a subform, but it works fine. I'm using Access 2010.
 
Hmmm. That's the very first thing I indicated: Access 2013.
Thanks!
 
My bad. It is. My neighbor isn't letting me sleep!
All I can tell you is that works fine in 2010.
Good luck!
 
try
Code:
Me.SubFormControlName.SetFocus
DoCmd.GoToRecord acActiveDataObject, , acNewRec
 
Thanks, PWise. Now I need to know where to put this code. What Event on what control is the place to put this code so that whichever tab of the tab control I click on, the subform (frmCars, frmTrucks, frmMotorcycles) on that tab goes to the new record on the appropriate form. I put the code you gave me in the On Click event of the tab control but then no matter which tab/page I clicked, the focus went to the page where I set the focus last. It did not work in the On Click event of the tab/page; that does not seem to be fired when I click the tab. So, if you have done this using the code above, where did you put it?

Thanks!
 
Code:
Select Case Me.TabCtName.Value
    Case 0
        Me.Page1SubFormControlName.SetFocus
    Case 1
        Me.Page2SubFormControlName.SetFocus
End Select

DoCmd.GoToRecord acActiveDataObject, , acNewRec
 
Okay. I figured out how to do this. The code below is put in the On Click event of the tab control itself (not the pages of the tab control). I had to test for which page was visible and then set the focus and go to the record as shown below:
Code:
Private Sub TabCtl0_Click()
  Select Case Me.TabCtl0.Value
    Case 0
      Me.Cars.SetFocus
      DoCmd.GoToRecord acActiveDataObject, , acNewRec
    Case 1
      Me.Trucks.SetFocus
      DoCmd.GoToRecord acActiveDataObject, , acNewRec
    Case 2
      Me.Motorcycles.SetFocus
      DoCmd.GoToRecord acActiveDataObject, , acNewRec
  End Select
 
End Sub
Note that I am setting the focus on the page, not the subform (e.g., not frmCars, etc.). Also, the Me.TabCt10.Value returns a numeric value (the page index value) for the page on top, beginning with 0.
On the side: It seems to me that the On Click event for the page should fire when one clicks the page tab where the name or caption of that page appears, but not so. That would be too simple and logical. The On Click event for the page does not fire until you click someplace on the page OTHER THAN the tab name/caption. Oh, well!
 
PWise,
Guess we were entering our last two posts at about the same time. Your code was a bit cleaner but essentially the same. In my post I included info for any who were wondering where to put the code.
Thanks, again! You pointed me in the right direction!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top