Results 1 to 14 of 14
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    Open to a tab

    I have a form [frmTraining]
    I put a tab on it [TabTrainingInfo]
    It has 4 tabs with a subform on each tab
    Tab 1 - [EnterTraining] with subform [frmTrainingEnter]
    Tab 2 - [TCOLETrainingHours] with subform [frmClassHoursTCOLE]
    Tab 3 - [OtherTrainingHours] with subform [frmClassHoursOther]
    Tab 4 - [RollCallTraining] with subform [frmTrainingRosterSubF]

    I'm trying to double click a record on Tab 2 and have it open on Tab 1. I tried this code, but it just gives me the debugger. I tried this code.

    DoCmd.OpenForm "frmTraining!TabTrainingInfo!frmTrainingEnter!frmT rainingEnter", , , "TrainingID=" & Me.TrainingID



    Tabs are confusing to me. Can this be done? Ideas?

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Just so you know, the control is called a tab control. The tabs are where the page name would show if you choose to display it. The area for the subform control that contains the form is known as a page. I make this distinction because Access also has a Tab view for forms and that's a different thing. If you're not hiding the forms all you have to do is set focus to the page. If you want the displayed record on another page to be the current record as well you can apply a filter to the form. Not sure what behaviour you'd get if you eliminate the error, because you don't really want to open the form using that method.

    If your pages have subform controls on them, is the source object property (that which dictates which form is in the subform control) being set on the fly, or are the forms not automatically displayed when you switch to a page?

    EDIT - You could also have the record id on the main form as well and the subform parent/child property should take care of keeping the related records in view.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    The subforms display automatically when switched to the page.

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Well I gave you 2 options
    - filter the subform when you dbl click subform on a page or
    - have a hidden textbox on the main form that holds the record id of the form you are on at any given point.

    If your main form has no recordsource you will have to set the record id for that control using code. When you switch pages, filter according to the record id. If it has a recordsource, you probably already have a control that contains the record id. Then use the parent/child properties as suggested.

    I think I'd be trying to eliminate the dbl click when I could just click on a page tab and have the subform be filtered. Having main form records would provide that capability. You don't even have to show them.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Tab controls are very confusing to me. It was just the only way I could think of to handle this particular type of information. I'm not sure how to set focus to the first page and then to the record that I need to be viewed. The parent/child is set to the EmployeeID so that it will display according to the person I'm trying to view.

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Maybe take a step back and explain the result you want rather than ask about how to do specific things. It may be that there's an easier or better way. You could also consider posting a zipped db copy if you think that would help. See How to Attach files at the top of the forum page.

    You wouldn't need to set focus to a page since you've said that the forms are always visible so you could refer directly to the form or perhaps one of its controls, but you could anyway with
    Forms!myFormNameHere.Page2.SetFocus (use your own form and page names).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    The first page on the tab control enters the training for the employee. I have the other 3 pages displaying the types of training the employee has. What I'm trying to do is to double click on the type of training and it displays the information on the first page. So, the first page will serve as an enter/display for the training.

  8. #8
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Can you give an example of what the data would look like on each page and what the linking fields are for each? Most times it is easier to see what you are trying to do with data examples then just descriptions. For example, so first tab has key of TrainingID for each training like Training 1, Traning 2, etc. Then the data on other tabs link to the TrainingID for the class from page 1?

  9. #9
    Join Date
    Apr 2017
    Posts
    1,681
    As I see it, you have some main form, with some info you haven't explained meaningfully yet (It can't contain employees trainings, as those are on 1st subform. And it can't be some general trainings registry, as I can't see any reason having this as top one). Then you have 1st subform, which probably is based on table of employees training sessions. And then there are other subforms, only reason i can see you having them is, that records there are extensions of records of 1st subform, as different types of training have different sets of data.

    You must have tables at start like:
    tblEmployees: EmplID, ForName, LastName, ..., EmplStatus
    tblTrainingTypes: TrainingTypeID, TrainingTypeText

    So I think you must have the main form (a single form) based on employees table (you can use it also to register employees).

    The 1st subform (a continuous form on 1st page) must be based on table of employees training sessions, like
    tEmplSessions: EmplSessionID, EmplID, TrainingTypeId, SessionDatetime, AnyNumberOfFiedsAppliedToaAllTypes.
    On main form, you need 2 hidden text box controls, which are updated with EmplSessionID and TrainingTypeId from active row of 1st subform (e.g. using Current event of 1st subform)

    On other pages, you have subforms based on tables like
    tblEmplSessionAddOn1: EmplSessionAddOn1ID, EmplSessionID, TrainingType1Id, AnyNumberOfFieldsAppliedSpecifcallyToType1
    tblEmplSessionAddOn2: EmplSessionAddOn2ID, EmplSessionID, TrainingType2Id, AnyNumberOfFieldsAppliedSpecifcallyToType2
    tblEmplSessionAddOn3: EmplSessionAddOn3ID, EmplSessionID, TrainingType3Id, AnyNumberOfFieldsAppliedSpecifcallyToType3
    Those subforms are practically subforms of 1st subform, and they are linked using hidden controls on main form (as they display always a single record, you can design them as single forms)
    You need to keep some control about adding records to those subforms, to avoid creating multiple records in 2nd level subforms for certain record in 1st subform.

    About terminology. The form which contains one or several subforms is main form for them. When you add a subform to main form, you really add a subform container control to it. The added form itself is really a source of added subform container. Access is going a bit sloppy with this, as it automatically names subform container with same name as form it has as source. Whenever I create a subform, I immedietely rename it (e.g. sfFormName), to avoid any confusion in future.

  10. #10
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    The first page on the tab control enters the training for the employee.
    That could mean anything. If it means it's where you add required training or training that was given or something else.
    I have the other 3 pages displaying the types of training the employee has
    That doesn't make sense to me. Why split it up into 3 pages? One pager per training module? What happens if you need to add a 'module' - you add another page? That's not the way to do it. A main form should show the employee details, subform(s) show required training as a whole and/or training that is current and/or overdue. It all depends on what you want to input and track.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    Let's make a few guesses.

    If the record is on Tab 2, I suppose you mean there's a record on the subform of Tab 2.

    Using the names you've provided, go to the code module of frmClassHoursTCOLE and let's suppose it has a control called MyControl, which is what you're trying to double click.
    Code:
    Private Sub MyControl_DblClick(Cancel As Integer)
        Me.Parent.Form.NameOfTabControl.Pages("Name of tab 1").SetFocus
        DoCmd.BrowseTo acBrowseToForm, "frmTrainingEnter", "frmTraining.SubformControlName", "TrainingID = " & Me.TrainingID
    End Sub

    Pay especial attention to:
    1. the name of the tab,
    2. the name of the form inside the subform control in Tab 1
    3. make sure the subform control that holds your frmTrainingEnter is NOT THE SAME NAME AS THE FORM THAT IS HOLDING for this to work

    Now, of course, there are other ways to go make a form go to a record, this is just one way. There is the GoToRecord, FindFirst, Filter, Bookmark methods, etc.

    EDIT: On a side note, the user experience and user interface that OP wants to give to his/her users should be subject for another thread. For this one, OP just wants to make a form reference.
    Please click on the ⭐ below if this post helped you.


  12. #12
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Thanks for the replies. I've been away getting ready for procedure and haven't been able to check in. Yes, I definitely agree that this is not the way to go. This was one of my very first attempts at this. It's very crude to say the least. I'm thinking of changing the whole thing if I can't get this working. I'm very bad on terminology especially on the Tab Control. With that, I really do appreciate all of the input.

    The way I have it set up is the main form is the employee form. It contains the employee name and few important information. The Tab Control: Page 1 is where I input the training information. It is linked to the main form by the EmployeeID. Each of the other pages are linked by EmployeeID as well. They are separated into different types of training so the user can just click on the tab and that information is automatically displayed. As I said, this is a very early idea that I had and it made sense at the time. I've learned a lot more and may have to redo the form.

    Edgar, I tried this as the first line of the code. I think that I may have done it incorrectly. Me.Parent.Form.TabTrainingInfo.Pages("EnterTrainin g").SetFocus

  13. #13
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    The first thing to remember or be aware of with tab controls is that they are simply extensions of the forms available area.
    Therefore any control on any tab can simply receive the focus, and the form will switch to the tab it is on.

    So switch focus to the subform control, then if necessary, to a control on the subform.

    From a subform:

    Me.Parent.YourSubformControlNAME.Setfocus

    Anywhere else on the main form:

    Me.YourSubformControlNAME.Setfocus
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  14. #14
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I really appreciate all of the help. I kept working on it, but I think Tab Controls are a bit too confusing for me. I changed the whole form. I made the main form something to enter the training. I added a list box to see the training that the employee had. I added a few more bells and whistles than that, but it works better now.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 11-26-2023, 02:58 PM
  2. Button to create/open or copy/open an excel file
    By petrikos in forum Programming
    Replies: 23
    Last Post: 10-15-2021, 07:00 AM
  3. Workbooks.Open won't open Excel file in Edit Mode
    By jeffhanner10@gmail.com in forum Programming
    Replies: 5
    Last Post: 02-15-2020, 11:51 AM
  4. Replies: 2
    Last Post: 04-25-2014, 11:22 AM
  5. Replies: 2
    Last Post: 08-07-2013, 07:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums