473,624 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Child Forms Using Main Form RecordSet

675 Contributor
I have a form with several bound textboxes. These are routinely updated by User. The table in RecordSource for this form currently has 8 fields not shown on this form, but which occasionally need to be changed by User. For this I have created an "Advanced" commandbutton, which opens a child form with controls to display the remaining fields.

I tried using recordsetclone to put the child form on the same record and recordset as the main form, but when the child form is closed, the clone is updated. Then the main form gets a write conflict when it tries to update the same record.

I found a sample code on another question which I have modified slightly and uploaded here. Original by FishVal I think.

Child form 1 seems to do what I need. Forms 2 and 3 pass references to a control, not the underlying data. As I have currently 8 fields, these seem inappropriate.

1) Open form = "frmmain", and move to record 2. Change Text2 to something else, i.e. "R 2aaa".
Move to record 3. Press the UnDo button, and the record is returned to record 2 and that is undone. But navagating to a new record should save the changes. Why wasn't record 2 saved when record 3 displayed?

2) Open form = "frmmain", and move to record 2. Click the Child Form 1 button. Change to something else, i.e. "Record 2ccc". Press submit. Press the UnDo button. Why isn't the command 'Undo' available now. The recordset for frmChild1 is the same as for frmMain, and the record has not been moved to another record, so why is the Undo unavailable?

3) The procedure "Private Sub txb_BeforeUpdat e..." in the code for child1 saves .OldValue for this textbox in case the "Cancel" button is pushed. This should not be necessary, as .OldValue is the value in the record, and should remain until the record is updated. .Text would be lost after the textbox were updated. If I comment out this statement, and put a breakpoint in "Private Sub btnCancel_Click ()". Me.txb.OldValue is the updated textbox value, not the recordset original value. Why?

4) If new record is selected and then child1 used, when I press "Submit" I get message "Update or CancelUpdate without AddNew or Edit." AllowAdditions = Yes on both frmMain and frmChild1, so why this message?

OldBirdman
Dec 29 '08 #1
11 4039
OldBirdman
675 Contributor
And now the Attachment...
Dec 29 '08 #2
OldBirdman
675 Contributor
I'll get it right yet!
OldBirdman
Attached Files
File Type: zip Child Form Same Recordset.zip (23.1 KB, 231 views)
Dec 29 '08 #3
nico5038
3,080 Recognized Expert Specialist
Without checking your sample, I do wonder or you considered to use the tab control ?
This "looks like" your additional [Advanced] button, but will allow you to have all fields on one form. You can even change the Tab into Buttons by changing the tab control's properties...

Idea ?

Nic;o)
Dec 30 '08 #4
missinglinq
3,532 Recognized Expert Specialist
I agree with Nic;o), tabbed pages would be the way I'd go with this, using the same table as the OP stated.

Linq ;0)>
Dec 30 '08 #5
OldBirdman
675 Contributor
No, but I didn't consider a larger monitor either. A tab control with one tab (or button) doesn't seem right. I don't see where this saves space, unless the forms 50+ visible controls are on one tab, and the 8 advanced controls are on the other. What is a "OP"?

I have now found the source of the sample code in topic/access/insights/842978-forms-interaction, by FishVal. I don't know how to directly point to a specific post but, OK, there it is.

This small database with table & forms seems to be here to use as a tool. Download it, study it, modify it, use it. But I can't make it work as I want, so I ask a question.

If my actual code is necessary, I will post it (you don't want to see it). If a few lines of code can demonstrate a problem, I prefer to post that. It is easier to understand, and might be easier for other users of this forum to apply to their problems. In developing a simple example, I often solve my own problems.

Of course there are other solutions to this problem. I could make all my controls smaller, with smaller fonts. I can't make the form larger, or it won't fit on my laptop screen. But if the controls are smaller, I can't read the data when the laptop is in my lap, because I'm getting old, and my bifocals are for close-up when looking down, and my lap is too far away, but my far reading means looking over the top of the bi-focal, and is a strain on my eyes, neck, and back. I could put the laptop in a place other than my lap, but then I could not take it with me, so I would just need the desktop. Also, as I get older, I want larger buttons and arrows to click. The motor skills to move the mouse/cursor aren't as good as they used to be. Microsoft recognizes this and addresses it in the control panel. But to make the mouse less responsive means the desktop computer, with a 22 inch monitor, needs too many passes over the mousepad to get from one edge of the monitor to the other.

If my question is inappropriate to this forum, please let me know. Otherwise, I would like to know how to open a child form, bind it to the same recordset as the parent form, and be able to cancel while the child form is open, or after it is closed but before the current record on the parent form is saved. I would also like it to work if the "New" button pressed, therefore creating a new record.

OldBirdman
Dec 30 '08 #6
FishVal
2,653 Recognized Expert Specialist
Hello, OldBirdman.

As soon as it was me to write this howto I'm expected to take responsibility. :D

@OldBirdman
Though I don't use menu undo command, I have a feeling that it is not a bug it is a feature. :)
Really, its behaviour is quite consistent. When current record is dirty it undoes changes in current record, otherwise it undoes last saved record.

2) Open form = "frmmain", and move to record 2. Click the Child Form 1 button. Change to something else, i.e. "Record 2ccc". Press submit. Press the UnDo button. Why isn't the command 'Undo' available now. The recordset for frmChild1 is the same as for frmMain, and the record has not been moved to another record, so why is the Undo unavailable?
As soon as frmChild1 is closed record it was pointed to is being automatically saved. Undo action is not available in main form because the record wasn't edited there. This makes sense if we will assume that particular form hold a "log" to roolback last edited record and Undo action uses this feature.

3) The procedure "Private Sub txb_BeforeUpdat e..." in the code for child1 saves .OldValue for this textbox in case the "Cancel" button is pushed. This should not be necessary, as .OldValue is the value in the record, and should remain until the record is updated. .Text would be lost after the textbox were updated. If I comment out this statement, and put a breakpoint in "Private Sub btnCancel_Click ()". Me.txb.OldValue is the updated textbox value, not the recordset original value. Why?
This was done to simulate Undo, when bound recordset will be updated on frmChild1 close.

4) If new record is selected and then child1 used, when I press "Submit" I get message "Update or CancelUpdate without AddNew or Edit." AllowAdditions = Yes on both frmMain and frmChild1, so why this message?

OldBirdman
Actually, I couldn't reproduce this behavior. However, there is another flaw - when input is cancelled in frmChild1 a new record in main form is being created all the same.

Frankly speaking I don't like this Method #1 because together with its "simplicity " it triggers too many automatic actions in a manner Access doesn't always expect.
I prefer to use Method#2 or, in special cases Method#3. As in examples from Absolute Position of a Control.

Regards,
Fish
Dec 30 '08 #7
nico5038
3,080 Recognized Expert Specialist
A tab control is used in general with two or more tabs.
Each tab "duplicates " the space of the form.
I normally "group" fields in logical units and place the group name on top.
This enables a user to navigate easily through the fields.
One form with 50 fields is certainly "too much" to grasp for a normal user and will probably require scrolling. By using a tab control and placing some 10 fields per tab will save the form scrolling and give an opportunity to "organize" the fields logically.

Just check the sample.

Nic;o)
Attached Files
File Type: zip TabbedMainform(2).zip (18.7 KB, 129 views)
Dec 30 '08 #8
OldBirdman
675 Contributor
First to my original 4 questions:
1) Yes, I now see that there is consistancy here. According to Access Help, moving to another record saves any changes before the move. Therefore, I wrongly assumed that my changes were complete and secure.
Even without an Undo button, a user can press cntl+Z and undo a previously saved record.

The question for #1 should now be: How do I write my changes to the table and prevent those changes from being inadvertently undone?

2) If form is Dirty, UnDo obviously should undo the recent, unsaved changes. If form is not Dirty, then for consistancy with #1 above, the last saved record should be undone. In this case, nothing is done. Not consistant.

3) I think this is not needed code. First, the way this sample code was written, it can't be used. The BeforeUpdate only fires when the form is closed, either by "Submit" or "Cancel". No code can use this held value. Adding another control to receive the focus can trigger BeforeUpdate without closing the form. Now varOldValue can be assigned a value. However, the statement "Me.txb = Me.txb.OldValue " in "Sub btnCancel_Click " will do the same thing.

4) I can't reproduce it either, NOW. But I did for several days, thru several reboots.


Second, Tabbed Forms:
This is really off-topic here. The sample file assumes that the 3 child forms are for different data. They are actually 3 ways to accomplish the same thing, and I don't believe a developer would give this choice to a user.
I find tab controls to be useful under two conditions. One is where the tabs have completely different controls, but all relate to a common theme. "Options" is an example here. Different tabs for different sets of options.
The other use mimics a ComboBox. Each tab presents the same data, but the underlying table is filtered according to the tab selected. A car dealer could have a tab for each brand sold, and therefore selecting "Toyota" would show a list of Toyotas in stock, and the "Scion" tab would similarly display a list of in-stock.
Tab controls can present their own problems, however. I tried to mimic a tab control on a tab control (Primary tab to display brand, secondary to select and display model in-stock). In DesignView the tab controls were not in the final position, so they could be selected. Moving the controls using VBA presented problems. Access doesn't store the controls relative to the tabcontrol, but to the form. When the tab control is moved, it is resized to accomodate the controls original position. I did not pursue this.

Third, Number of Controls on Form:
There are 2 variables here, controls on a form, and number of mouse clicks or keypresses to do the common tasks. The trick is to find the ideal point. A table of 10K records using a native language to identify the correct record would require an average of 2,500 records displayed using the Access navigation buttons(First, Previous, Next, Last). Guessing by selecting the record number, typing over it, and pressing Enter would lessen the records viewed, but is clumsy, involving both the mouse and the keyboard. Having an easy selection process always visible takes space but makes the task easier. Having to click the "Select" tab, do whatever is necessary here, click the "View" tab to see if selection was successful, and repeat if necessary is labor intensive. I work with names (people & business), titles (movies, books, music albums), and bird species. All these may have duplicates and/or alternate names.
Now that the correct record is displayed, I want to view/modify fields not displayed. The sample, "Child Form Same Recordset.zip", seemed to have the solution to modifying the record, but I had questions. That is what this thread is about, I hope.

OldBirdman
Jan 3 '09 #9
nico5038
3,080 Recognized Expert Specialist
I see you're not grasping the way a tab-control can be used, so I rest my case.

Success with your application.

Nic;o)
Jan 3 '09 #10

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

Similar topics

0
2494
by: sshuangw | last post by:
Hello: I am encountering a very weird issue with MDI child, Overriden WndProc function and hidden form. Basically, the application has two forms, Form1(parent form), Form2(Child form), Form2's WndProc method is overriden, if the message is CLOSE message, just hide the form. I first initialize and show the child form, then close it by clicking the Close(X) button, the overriden WndProc method gets invoked, and the form is hidden. Then
3
5609
by: James Spibey | last post by:
Hi, I have an MDI application which has aboout 10 child windows. The way the app needs to work is that only one window should be visible at a time and it should be maximized within the parent window. I have set all my child windows to be WindowState.Maximized but after showing 2 or 3 windows, the windows all drop back to Normal state. I have tried various things to overcome this inclusing overriding OnResize etc but none seem to give...
3
9690
by: Maheshkumar.R | last post by:
Hi groups, How i can command over the MDI CHIlD forms created dynamically at runtime from PARENT. Let say, i have generated 5 mdichild forms, but i want to work with child form1 from MDI parent menu functions. if i select draw line in MDI parent, the line should be drawn in current active child..any URLS for this or guide me to achieve this communication... -- Mähésh Kumär. R
10
4008
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the application. What should happen, is that the main MDI form should close, taking the child forms with it. There is code to loop through the child forms, remove the controls on each of them, and then close the form, but this code should execute only...
0
1867
by: Bruin | last post by:
Hi All, I'm having a problem with MDI child forms when the reference to the MDI Parent is set in a Control library. (Sorry for the long post) I have an control library assembly which holds all of my base classes including my base MDI Container form and my base MDI child form the mdi container has a singleton which returns an
2
2439
by: Matt | last post by:
Ok here is my problem: I have a MDI parent form called "Main" that I declare in a public module when I start up my program. This form holds the drop down menu that allows my users to access all of the child forms. Now lets say I have a child form called "Child." When I open up that child form from "Main" I shut off the menu on "Main" so that the user cannot open up any other forms while they are in the "Child" form.
13
2935
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the events.. But the regular forms that are also open do not receive that event. This is true whether there are child forms open or not.
12
6221
by: Phil | last post by:
I can check for MdiChildren.Length=0, but which event handler should I put this in to detect when a child window is closed? TIA Phil.
0
2037
by: emalcolm_FLA | last post by:
Hello and TIA for any help with this non profit Christmas assistance project. I have an applicant (app history) and child (child history) tables (4 total). I need to grab the next available (in house case number, appt date and time) for the applicants yearly history and the childs yearly history and then print a report with the applicants info and this in house case number. The forms are linked with ID_app (from the applicant table).
0
8242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8341
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
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
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
4084
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
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1488
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.