INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

(OP)
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!

RE: Open a continuous form on a tab control to a new record

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.

RE: Open a continuous form on a tab control to a new record

(OP)
Hmmm. That's the very first thing I indicated: Access 2013.
Thanks!

RE: Open a continuous form on a tab control to a new record

My bad. It is. My neighbor isn't letting me sleep!
All I can tell you is that works fine in 2010.
Good luck!

RE: Open a continuous form on a tab control to a new record

try

CODE

Me.SubFormControlName.SetFocus
DoCmd.GoToRecord acActiveDataObject, , acNewRec 

RE: Open a continuous form on a tab control to a new record

(OP)
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!

RE: Open a continuous form on a tab control to a new record

CODE

Select Case Me.TabCtName.Value
    Case 0
        Me.Page1SubFormControlName.SetFocus
    Case 1
        Me.Page2SubFormControlName.SetFocus
End Select

DoCmd.GoToRecord acActiveDataObject, , acNewRec 

RE: Open a continuous form on a tab control to a new record

(OP)
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!

RE: Open a continuous form on a tab control to a new record

(OP)
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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close