473,666 Members | 2,144 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Popup Subform not retrieving parent form value

5 New Member
Okay this is the situation I have two forms and they have a 1:M relationship. I don't have enough space screen-wise to do a traditional "drag form to form" to create a subform so what I did was create command buttons that open the subform when I click on it.

I added a filter to the VBA that filters the results of the subform to display only records that match the linking field of the two forms. And it those and would filter but..I am having problems when I putting information into the subform. The issue is the foriegn key value(CaseNo) (in the underlying table: tblHearings, fyi. the form name is frmHearings, and table name is tblHearings) that is in subform does not get populated with the primary key value(CaseNo) of the parent form that entered before opening the subform. The field that links the two table together is: CaseNo. This is the code I used:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command52_Click() 
  2. On Error GoTo Err_Command52_Click 
  3.  
  4.     Dim stDocName As String 
  5.     Dim stLinkCriteria As String 
  6.  
  7.     stDocName = "frmHearings" 
  8.  
  9.     stLinkCriteria = "[CaseNo]=" & "'" & Me![CaseNo] & "'" 
  10.     DoCmd.OpenForm stDocName, , , stLinkCriteria 
  11.  
  12. Exit_Command52_Click: 
  13.     Exit Sub 
  14.  
  15. Err_Command52_Click: 
  16.     MsgBox Err.Description 
  17.     Resume Exit_Command52_Click 
  18.  
  19. End Sub 
  20.  
to filter the informtion that appears in the subform and it does filter the information if I manually type in the matching, in my case "CaseNo" in the "tblHearing " table but it shouldn't work like that. I want the foreign key field in that "TblHearing " table to be automatically populated, on the table level, with the primary key value of the parent form. Can you or anyone else lend some assistance? I have been racking my brain for a few days trying to get this and I am drawing complete blanks.
Oct 30 '08 #1
6 10753
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. What Access does when the parent-child relationship is set is to automate the default value of the child field - which you have not done when opening the form manually. As there is no default value set you will indeed find you can filter but not get the 1-m relationship to work for new records.

The simple solution is to set the default value property for the CaseNo field immediately after you open the form. The syntax for this is very similar to the syntax for the filter statement you are already using. Include the following line immediately after your DoCmd.OpenForm statement:

Expand|Select|Wrap|Line Numbers
  1. Forms(stDocName)![CaseNo].DefaultValue = "'" & Me![CaseNo] & "'"
-Stewart
Oct 30 '08 #2
solom190
5 New Member
Stewart, First I'd like to take you for the reply, and answering my question. I put in the code that you suggested and now I am getting what I believe to be an error message when I click on the command button. What the error message says is "Object doesn't support this property or method." I tried putting the code on other command buttons and I get the same message. I'm trying to fix the problem and will more than likely be trying the rest of the day. If you or anyone could offer some insight it would be greatly appreciated.
Oct 31 '08 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. Obvious question: you do have a control placed on the form you open which will implement field CaseNo, don't you? If you don't, you will need to add it to the form as you will not be able to reference the defaultvalue property of a non-existent control.

If you do have such a control in place, make sure it is named the same as the field concerned. Also, it is on the form you are opening, and not in a subform within that form, isn't it? This is important, as the syntax would be different for a subform within a main form:

Expand|Select|Wrap|Line Numbers
  1. Forms(stDocName)!NameOfSubform.Form![CaseNo].Defaultvalue = ...
-Stewart
Oct 31 '08 #4
solom190
5 New Member
Thanks Stewart. Before I even posted my question I figured that the issue might be with not having control on the form that held CaseNo, because the first design didn't so created two forms and was testing the code on both of them. I came across another issue with code you just provided and was just playing around with it an got it to working. I changed it to.

Expand|Select|Wrap|Line Numbers
  1. Forms(stDocName).Form![CaseNo].DefaultValue=...
  2.  
Which is actually close to what you first suggested. It works on the form, course, the form with the control of CaseNo on it and doesn't on the one with CaseNo. Only issue now is that it won't allow you to close that subform until the "cursor" from the main form has been moved and technically "saved" before you can close the subform. But that is neither here nor there and is another issue that can be saved for next week. I appreciate all your help. Thank you.
Oct 31 '08 #5
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. Glad you got this working. Please note that Forms(name of form).Form is the same as Forms(name of form) - so the code you've settled on is indeed what I suggested in my first reply.

On the matter of saving the main form record, you can test whether or not the record has been changed using the form's Dirty property before you open the subform:

Expand|Select|Wrap|Line Numbers
  1. If me.Dirty then me.Dirty = False
This simple line of code actually saves the record if it has been changed. This is necessary if you have created a new one-side record and want to add many-side records that correspond, because until you save the record you will not have a match between the one-side and the many-side keys (as the one-side primary key will not actually exist as far as the DB is concerned).

-Stewart
Oct 31 '08 #6
jbrumbau
52 New Member
Though VBA code works in form view, it actually doesn't work when you do
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand acCmdPrint
Instead, I took the unbound control of interest and referenced my parent control txtSpecCaption by doing:
Default Value = [Parent].[txtSpecCaption]
No code required and it works like a charm.
Feb 3 '11 #7

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

Similar topics

1
2116
by: VbUser25 | last post by:
hi.. i have a drop-down menu with a list of products.when i select any one product i open a popup displaying hte product categories in it.i then enter the no. of items i want.and finally when i click to the submit button i want to display a summary of selected item in the parent form.to make it more elaborate: i have 3 items in a drop-down menu and each item has further 10 different types of products.
25
10220
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the data in each record, which includes the ID of the father and the mother (who also have records in the table). One record per form. I have a Tab Control in the form, and in one of the tabs I have a subform (sfmSiblings) in which I wish to list...
5
5249
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test box that is populated with the code =subfrm_media_review_sec_party.Form!first_name & " " & subfrm_media_review_sec_party.Form!last_name It works except that when I flip through the names it populates the parent form with the name of what ever...
20
10809
by: Robert | last post by:
Need some help to stop me going around in circles on this one.... Have a nested subform (subform2) which simulates a continuous form for the record on the parent subform. Subform2 has rows of either an option button plus two text fields or a checkbox plus two text fields Am wanting to save the user entries into an underlying table. Tag property for each option button, check box or text field has the value of the key
1
4128
by: ctbang | last post by:
I have a JSP page with a form containing 2 text fields (infact there are many) and I want to add the feature of a help button (instead of drop down). On clicking the button it should popup a jsp page displaying records, afer selecting the record and clicking ok the window should close and populate the corresponding data to the parent form text fields. Infact the popup will be calling a controller servler, it will create a arraylist...
4
12584
by: neena | last post by:
Hi I am uing C#.net & using javacript for a popup window. I've a form and there is a button named Categories. When it is clicked, it will open a new window for the selection of categories. When the categories are selected from ListBox ,and the submit button of the popup window is clicked, the category id value should be set in the parent form and the popup window will close. the problem is that the parent window form doesn't get the...
13
3268
by: bitsnbytes64 | last post by:
Hi, I have a form which contains a subform. Both are were creetd using the form wizard and are bound by the column IXO_NR (on two different tables), which is the control source for a textbox on both the parent and subform. The intent was to default the subform's IXO_NR to the parent form's IXO_NR, then requery the subform to prevent the user from having to scroll through all of the subform's records to find the one they may be looking for....
1
2672
by: ckrows | last post by:
Hi guys, I have a parent form that displays the subform. The subform query has a link back to the original ID. I was having issues keepign them in sync, since every parent may not need a subform. So i am trying to create an entry in the subtable whenever the parent is opened. This way it is always in sync and has it ready. VBA is not recognizing the field i want to upodate (tbldashlink) and i get a compile error each time. Also one more...
7
4097
by: bbobely | last post by:
Hi, I've built a sequence that works thusly: User chooses a value from a combo box. This causes a query to run displaying records with a field value matching the combo box in subform 1. Then, the record ID of whichever record is active in subform 1 is used to populate a text box. This text box has its after update property enabled that runs a second query which should populate a second form by matching the record id to entries in a...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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
8639
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
6198
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
5664
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
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
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
1775
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.