473,695 Members | 2,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

events within child subforms from a parent master form

8 New Member
I have a question concerning the need to trigger events within a "child" subform which is itself enbedded within a master "parent" form and which is accessible via a tab in the parent form. Becuase this is all very difficult to explain in words, please bear with me as I endevour to explain what it is I am trying to do. It would be helpful if I could attach a graphics file to this posting that would help explain what it is I'm trying to achieve in the form of a daigram but as this isn't possible, please bear were me. Before I continue, I should just say that I am a newcomer to MS Access and to VBA programming in general.

I am seeking to build an MS Access application that will hopefully be accesible via a single page. By page, I simply mean, single window. Because my application uses a large number of different forms both to input and display data, I have decided to create a single "page" and have multiple tabs within it. It is within each of these tabbed areas that I want to embed a different subform. Each subform does of course have it's own specific function. For the sake of clarification, I shall call the single displayed page within a single window, the "parent" form and each of the subforms within each of the respective tabbed areas, a "child" form. (I hope this all makes sense as I did warn you that explaining all of this in words was going to be complicated ... )

Now becuase it is the case that there are some "global functions" (events) that I would like to apply to all of my subforms, I have decided to divide the parent form into threee succient areas or "frames" as I shall call them: Top, main and bottom respectively. To be clear, within the "main" frame, the tabbed areas exist with their corresponding subforms. Within the "top" and "bottom" frames, button designed to invoke global functions exist.

What I want to do is to have some record navigation and form operation buttons appear within the top and bottom frames that, when clicked on, will trigger an event within the particular subform that appears at that time depending upon which tab within the main frame has first been selected.

As I said, the buttons I want to appear in the top and bottom frames are record navigation buttons (i.e., go straight to the next, previous first or last record) and form operation buttons - specifically: "print current record", "edit current record", and "delete current record"). What I'm trying to achieve is to have these functions operate irrespective of what form is currently being displayed in whatever tab has been selected.

The problem I am having is that although I can get all of my subforms to work perfectly when used in isolation, and although I can my main frame buttons to work perfectly on data displayed within the parent form as a whole, I cannot get the two to work together when combined in the manner described. What I therefor want to know is how to achieve this.

To help clarify, I should tell you that I have a total of 6 tabs within the parent form. Becuase I have 6 tabs, I also have 6 corresponding child subforms. You may wonder why I bothered to create these child subforms first and embed them within the parent form and the reason is that it was easiest to develop each of them in insolation and ensure that each of them work. My thinking was that having done so, I could then just drag and drop them into the parent form and hey presto, everything would work as planned.

THESE ARE THE ASSUMPTIONS I AM WORKING FROM:

1. Tab Control name: TabCtl1
2. Number of Tabs/child subforms: 6
3. Tab/child subform Captions: Page1, Page2, Page3, Page4, Page5, Page6
4. Tab/Child Form Names: pgeOne, pgeTwo, pgeThree, pgeFour, pgeFive, pgeSix
5. The record navigation button functionality has been achieved by means of a module called: FormNavigationB uttons


Here follows the code I am using for the 'FormNavigation Buttons' module:

Expand|Select|Wrap|Line Numbers
  1. Function GotoPrevious()
  2.  
  3.     'if an error happens, we must be on the first record
  4.     On Error GoTo OnFirstRecord
  5.  
  6.     'got to the first record
  7.     DoCmd.RunCommand acCmdRecordsGoToPrevious
  8.     Exit Function
  9.  
  10. OnFirstRecord:
  11.  
  12.     'if an error has occured, we get here
  13.  
  14.     'display a message to say what the problem is ...
  15.     MsgBox "Already on the first record!"
  16.  
  17.     '... and carry on immediately after the offending line
  18.     Resume Next
  19.  
  20. End Function
  21.  
  22. Function GoToNext()
  23.  
  24.     'if an error occurs, logically we must be on the last record
  25.     On Error GoTo OnLastRecord
  26.  
  27.     'go to the next record
  28.     DoCmd.RunCommand acCmdRecordsGoToNext
  29.     Exit Function
  30.  
  31. OnLastRecord:
  32.  
  33.     'if an error has happened, we get here
  34.  
  35.     'display a message to say what the problem is ...
  36.     MsgBox "Already on last record!"
  37.  
  38.     '... and carry on immediately after the offending line
  39.     Resume Next
  40.  
  41. End Function
  42.  
  43. Function GoToLast()
  44.  
  45.     'Because we're not at either the first or last record, we can execute code directly
  46.  
  47.     'go to the last record
  48.     DoCmd.RunCommand acCmdRecordsGoToLast
  49.     Exit Function
  50.  
  51. End Function
  52.  
  53. Function GotoFirst()
  54.  
  55.     'go to the first record
  56.     DoCmd.RunCommand acCmdRecordsGoToFirst
  57.     Exit Function
  58.  
  59. End Function
  60.  
Now I know how to give focus to the tabs but don't know how to apply the following code to that that I have already:

Expand|Select|Wrap|Line Numbers
  1.    Method 1:
  2.    Me!TabCtl1.Pages(0).SetFocus - set Focus to the 1st Tab
  3.  
  4.     Method 2:
  5.     Me!TabCtl1.Pages!pgeThree.Setfocus - set Focus to 3rd Tab
  6.  
  7.     Method 3:
  8.     Me!TabCtl1.Pages("pgeFour").Setfocus - set Focus to 4th Tab
  9.  
  10.    Method 4:
  11.    Me!TabCtl1.Value = 4 - makes the 5th Tab active
  12.  
  13.    Method 5:
  14.    SendKeys "%a" - makes the 6th Tab active (a is a 'Hot Key' in the Caption of this Tab.
Please can someone tell me how I would need to alter my module code so that it resulted in what I'm looking to achieve.
Dec 7 '07 #1
4 6050
FishVal
2,653 Recognized Expert Specialist
Hi, Harlequin.

Try the following code. Hope it is quite self-explaining.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub btnNext_Click()
  3.  
  4.     With Me.TabCtl0 'get reference to tab control
  5.         ' get reference to an active page subform control
  6.         ' supposed it is the first one or even the only one
  7.         With .Pages(.Value).Controls(0)
  8.             .SetFocus
  9.             'trap an error when tries to go to a record after the last one
  10.             On Error GoTo EndOfRecords
  11.             DoCmd.GoToRecord , , acNext
  12.         End With
  13.     End With
  14.  
  15.     Exit Sub
  16.  
  17. EndOfRecords:
  18.  
  19. End Sub
  20.  
  21.  
  22.  
  23. Private Sub btnPrev_Click()
  24.  
  25.     With Me.TabCtl0
  26.         With .Pages(.Value).Controls(0)
  27.             If .Form.CurrentRecord = 1 Then Exit Sub
  28.             .SetFocus
  29.             On Error GoTo BeginOfRecords
  30.             DoCmd.GoToRecord , , acPrevious
  31.         End With
  32.     End With
  33.  
  34.     Exit Sub
  35.  
  36. BeginOfRecords:
  37.  
  38. End Sub
  39.  
  40.  
Regards,
Fish
Dec 7 '07 #2
Harlequin
8 New Member
Hi Fish,

Thank you for very helpful posting. I'm glad my literal explanation was sufficiently clear that you understood what it is I'm trying to achieve.

I do however have one followup question for you. At the momement, I've put all the VBA code to work with buttons appearing within the top and bottom frames into modules - thinking that this would be the easiest way to reuse the code should I need to. You'll note also that my module code uses function procedures rather than sub proceduces. My thinking here was that since a function always performs and an action and returns a particular result, and that that is precisely what I wish to achieve with these buttons, that that was the best way to proceed.

I note however that your code uses procedures and I'm unsure as to (a) where to call them from and (b) where to associate them with my parent form.

Can you clarify this please?

Many thanks,

Harlequin
Dec 8 '07 #3
Harlequin
8 New Member
Apologies for following up on my last post but I forgot to add that if at all possible, I'd like to adapt my existing module function code as this works very well but only with the parent form used in isolation of the child forms.

Basically, what i want is to adapt my existing code to work within the secenario I've described. It is of course about how to give focus to the child subforms within the parent form.
Dec 8 '07 #4
FishVal
2,653 Recognized Expert Specialist
Hi, Harlequin.

I have even better solution for your problem. What about using native Access Navigation Bar on the main form to browse records on a subform on an active Tab control?

Here is very simple code to dynamically connect main form to an active subform RecordSet.

In main form module
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     ConnectMainFormToActiveSubform
  3. End Sub
  4.  
  5. Private Sub TabCtl0_Change()
  6.     ConnectMainFormToActiveSubform
  7. End Sub
  8.  
  9. Private Sub ConnectMainFormToActiveSubform()
  10.  
  11.     With Me.TabCtl0
  12.         Set Me.Recordset = .Pages(.Value).Controls(0).Form.Recordset
  13.     End With
  14.  
  15. End Sub
  16.  
Dec 8 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
8478
by: Mark C | last post by:
I have a unbound form with a tab control with four tabs in an Access 97 database. On each tab I have a sub form each form on the sub forms is bound to its own table. Each table has a field that can link them all together. I have put an invisible unbound control on the master form that gets populated on open. I set the link child and link master of each sub form to the unbound control on the master form. When the form opens all the subforms...
13
7406
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've created forms for both those tables, and inserted the child table form into the master table form as a subform. It works just as it is supposed to, in that I can create a new master record, and then add detail records.
8
4931
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender, System.EventArgs e) { MessageBox.Show("keyboard button pressed!"); } Following is the code to load the frmTestBaby
1
1957
by: Bill Borg | last post by:
Hello all, Simple chat app, where the site owner has a master window with all requests for chat, status of each room, etc., and child windows for each separate chat in which the owner is engaged. When the owner closes one of his child windows, I want to update the master window. I understand "reasonably" well how to go about this. The master window launches the children, and maintains an associative array to keep track of each one....
12
2788
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown when menu items are clicked.Besides these i would like to put a custom status bar. Any error message encountered in any of the webpage will be displayed in the banner. The problem iam encountering is how to access the customer status bar in child...
11
8124
by: elaina | last post by:
Hello again. I have setup a master form linked to a subform (actually nested subforms, but the top level subform is the one giving me trouble.) When entering data, the forms all appear to work correctly, but the moment that you change the record in the parent/master form, the forms "lose" all of the data we enter from the subforms. Upon examination of the tables, I found that the master key is not being populated into the top level subform,...
4
8040
by: Doc John | last post by:
I have a "global" MDI which will contain everything in the application. Since the application itslef will include three different "environments" with their own child Forms, I was wondering if I could load any of these MDI containers (or environments) so that their parent is the global MDI form. Basically it's like having three different applications opening inside my main MDI form. Thanks.
2
1634
by: dbstrat | last post by:
Hi. I have 3 tables that I need to display on a master-child form/subform. Think of it as Orders and Order Details. The tables are Orders OrderDetails VendorItems
21
3360
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters a zipcode that is unknown this form will open. I don't want users to modify any of this customers data until they close the zipcode form. Normally this can accomplished using a modal form, however this prevents me from opening a new copy of...
1
8826
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8818
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6487
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5832
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4338
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2996
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2261
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.