473,659 Members | 3,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pass a value from a main form to a subform

14 New Member
Hi There,

I'm a beginer in Access and VB.
In my Database, I've got a form with a subform.
the subform is a query from a table different than the table of the main form. those tables don't have a link yet.

the main form is being use to create a new entry/ a new row in the table.

What I want to do is use the primery key from the main form and copy the value in a field in the subform. In the subform, I first need to select some rows. The value has to be copied when I select the item, there is a field beside where the value should be.

I try different thing but I haven't find a solution that work.
one of the solution, the most logical for me, is to add an event 'on click' when I choose which element I want in the list. I used the expression builder but it doesn't work. one of the expression was something like this:
Expand|Select|Wrap|Line Numbers
  1.  =([Transaction]=[Forms]![Kit Transactions Form]![ID])
This is not working, I'm not sure why, and I haven't find any function or expression that could do the trick.

This will be used later one to link the two tables and create reports.

I hope anyone understood what I want to do, it is quite complicated to describe everything in words. I attach a print screen of the form and subform.

Any sugestion is welcome.

Thanks in advance
Attached Images
File Type: jpg Image1.jpg (11.8 KB, 1599 views)
May 11 '10 #1
27 29259
tragaz
14 New Member
Hi again,

I just try to put this code in the 'on click' event

Expand|Select|Wrap|Line Numbers
  1. Private Sub Used_Click()
  2.     Forms![Kit Transactions Form]![Courier Bag Inventory Query subform].Form!Transaction.Value = Forms![Kit Transactions Form]!ID.Value
  3. End Sub
It still doesn't work

Thanks for any help
May 11 '10 #2
MMcCarthy
14,534 Recognized Expert Moderator MVP
You actually have to take this back to the relationship between the two tables.

If we call Table1 the name of the table behind the main form and Table2 the name of the table behind the subform. Now Table1 has an ID field called Table1_ID and Table2 has an ID field called Table2_ID and a foreign key called Table1_ID.

Now it's important that Table2_ID has a data type of autonumber. There are other ways of doing it but this is the simplest. Set the default value of of the Table1_ID field in Table2 to ...
Expand|Select|Wrap|Line Numbers
  1. =Forms!MainFormName!Table1_ID
Now set the parent child relationship between the main form and the subform to be based on Table1_ID.

You will find that as you start to add value to any of the other fields in the subform, that Table2_ID will generate automatically as it is an autonumber and the value in Table1_ID in the subform will reflect the value of Table1_ID in the main form.

I hope I've explained this clearly. Let me know if you can't follow.

Mary
May 11 '10 #3
tragaz
14 New Member
Thanks for this,

the thing is that in Table2, there are already some existing field, I don't want o create new ones, at least not in this case.

In fact it is in Table1 that a new row is created by filing up the main form.
I actually want to copy the value of the Table1 primery key newly created to some field in Table2, by selecting in the subform which field to copy.

You're solution is sort of work since in the subform, if i wanted to create a new row, then the Primery key would be copied, but it does't copy in field that I'm selecteing afterthat...

Hope it is clear.
Philippe
May 11 '10 #4
MMcCarthy
14,534 Recognized Expert Moderator MVP
@tragaz
I don't understand your reply. I think it's best if you use the table names and field names you are actually using so I can better follow what you are saying.
Also please give the metadata of the tables so I can see the existing structure.

Here is an example of how to post table MetaData :
Table Name=tblBooking s
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. StudentID; Autonumber; PK
  3. Family; String; FK
  4. Name; String
  5. University; String; FK
  6. Mark; Numeric
  7. LastAttendance; Date/Time
May 11 '10 #5
tragaz
14 New Member
Hi msquared

Sorry for the confusion, I though that using the name that you used in your example would be easier for you to follow.

Ok so I've got 2 tables:
Table Name = Kit Transactions
Expand|Select|Wrap|Line Numbers
  1. ID; AutoNumber; Pk
  2. Kit Barcode; Text; Fk
  3. Courier Bags; Number
  4. Courier Bag Barcodes; Text
  5. Cotton Rolls; Number
  6. Vials; Number
  7. Forceps; Number
  8. Dispatched; Date/Time
  9. Client; Number; Fk
  10. Received; Date/Time
  11. Chilly Bag Returned;T ext
  12. Courier Bags Returned; Number
  13. Cotton Rolls Returned; Number
  14. Vials Returned; Number
  15. Forceps Returned; Number
  16. Received By; Number; Fk
  17. Invoiced; Date/Time
  18. Notes; Text
Table name: Courier Bag Inventory
Expand|Select|Wrap|Line Numbers
  1. ID; AutoNumber; Pk
  2. Track n Trace number; Text
  3. Used; Yes/No
  4. Transaction; Number; Fk
Alright, so my main form is based on the table Kit Transactions
the subform is Courier Bag Inventory based on a query that shows only the data where Used='No'
In the subform, Used is represented by a checkbox.

What I want to do is when the user click on the check box, the value of Kit Transactions.ID is copied in the Courier Bag Inventory.Trans action

Also, the main form is used to create a new data in the table Kit Transactions and update data in other tables links to it. One of the update that has to be done is copying the value of the new ID into the selected items of the Courier Bag Inventory

Hope you understand
May 11 '10 #6
NeoPa
32,568 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. Private Sub Used_Click()
  2.     Forms![Kit Transactions Form]![Courier Bag Inventory Query subform].Form!Transaction.Value = Forms![Kit Transactions Form]!ID.Value
  3. End Sub
Taking a step back for a second...
This appears to me to be workable. It matches the format described in Referring to Items on a Sub-Form.

I suspect that one of these forms (main or sub) actually contains the control Used. This form can be referred to more simply as Me.

Can you say exactly what is failing here? I would certainly consider progressing on this front if possible, as it is more precisely related to your problem.
May 12 '10 #7
tragaz
14 New Member
Hi Neopa

the control Used is in the subform. I know that I can refer to the subform as Me but I wanted to be sure of what I was writing.
but just to be sure, if I want to use Me, should it be like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Used_Click() 
  2.      Forms![Kit Transactions Form]!Me.Form!Transaction.Value = Forms![Kit Transactions Form]!ID.Value 
  3. End Sub 
Or like that:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Used_Click() 
  2.      Me.Transaction.Value = Forms![Kit Transactions Form]!ID.Value 
  3. End Sub 
I'm not sure what is going wrong because when click on the control Used it appear that the value hasn't been copied. well at least the value is not showing in the field Transaction as well as in the Table Courier Bag Inventory where this field is... Any idea?

I also tried to add Me.Transaction. Requery after the precedent code, thinking that it might actually refresh the value of Transaction but it's not. the code looked like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Used_Click() 
  2.      Forms![Kit Transactions Form]![Courier Bag Inventory Query subform].Form!Transaction.Value = Forms![Kit Transactions Form]!ID.Value
  3.      Forms![Kit Transactions Form]![Courier Bag Inventory Query subform].Form!Transaction.Requery 
  4. End Sub 
With Me:
(sorry for the repition I'm just not sure if I'm using Me correctly or not)
Expand|Select|Wrap|Line Numbers
  1. Private Sub Used_Click() 
  2.      Me.Transaction.Value = Forms![Kit Transactions Form]!ID.Value
  3.      Me.Transaction.Requery 
  4. End Sub 
Thanks in advance for any help
May 12 '10 #8
NeoPa
32,568 Recognized Expert Moderator MVP
tragaz: should it be like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Used_Click() 
  2.      Forms![Kit Transactions Form]!Me.Form!Transaction.Value = Forms![Kit Transactions Form]!ID.Value 
  3. End Sub 
Or like that:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Used_Click() 
  2.      Me.Transaction.Value = Forms![Kit Transactions Form]!ID.Value 
  3. End Sub 
.Value is the default property of most controls so is generally redundant.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Used_Click()
  2.      Me.Transaction = Forms![Kit Transactions Form].ID
  3. End Sub
You could also say :
Expand|Select|Wrap|Line Numbers
  1. Me.Transaction = Me.Parent.ID
This works better if you ever need the subform to be contained on any other form than [Kit Transactions Form].
tragaz: I also tried to add Me.Transaction. Requery after the precedent code, thinking that it might actually refresh the value of Transaction but it's not.
The format would be :
Expand|Select|Wrap|Line Numbers
  1. Call Me.Requery
but it should not be necessary in this case.
May 13 '10 #9
tragaz
14 New Member
Neopa,

I wrote the command as you said, for the correct way:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Used_Click() 
  2.      Me.Transaction = Forms![Kit Transactions Form].ID
  3. End Sub 
Unfortunately, it doesn't work. When I click on the Control Used, the value is not copied, well at least I don't see the value in the Transaction control and in the field in the table.

Any idea how I could do that?
May 13 '10 #10

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

Similar topics

9
3331
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text field called . It gets populated based on what the user selects in a field on the sub form (code in the AfterUpdate Event). Here's the issue. If the user deletes a subform record. The field on the main form shows null even if there is a value in the preceding subform record. What I'd like it to do is immediately refresh to
1
2192
by: Bill Strass | last post by:
Problem: Access main form/subform as front end to SQL Server backend. Add/edit via subforms work fine. Not so with main form. Set up a master-detail form-subform using two views linked from SQL Server. The subform allows inserts an updates, while the main form will not. The only solution I can think of is to recreate using tables imported from SQL Server, so that the data is all local. This is despite the fact that the views in SQL...
0
1428
by: Deano | last post by:
I have a main/subform arrangement which works well. The main form's parent records are about employees. The subform calculates their salary. I have now decided that the user can enter some splits in a popup form that I have built. So they click the Splits button and they can enter e.g 0.4 and 0.6 or any combination as long as it comes back to 1 (the reason for this is so they can allocate parts of the salary to different code areas)....
4
7002
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the user enters the last qualifying field on the main form. In one case this works fine, the subform shows the data the user wants to update -- which means showing all the data put in previously (ie showing this via the requery and the continuous...
18
13592
by: Darryl Kerkeslager | last post by:
I don't do much with subforms - in fact I've deliberately avoided them - but .... I have a tab control that will contain several subforms, each bound to a separate table, and each table/subform will relate to the same person - but the subform data will not be 'linked' to the main form. I want to have one Cancel button for all the undo operations on all the subforms, so the individul subform's Public Sub, Form_Cancel will be called...
5
3989
by: Ivan | last post by:
I am used to VB6 and am not sure how to do this in Vstudio .NET. I have a main form which calls other forms. I want to disable that main form while other ones are called. I tried hiding it and creating a new instance of the main form when returning to it but than my application is just creating more forms. How do I hide the main form and return back to it when exiting another form?
3
2960
by: Steve | last post by:
Is there a way to put a main form/subform in a continuous form so I can scroll through all the records in the main form? Thanks!
1
1542
JustRun
by: JustRun | last post by:
hi, I have a problem with passing the value from a Form that "user should choose a start date and end date" to a Form that display the result in a Crystal Report Form Actually it gives this error at runtime: "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM" 'The form that dates will be picked from
0
1490
by: farid121 | last post by:
I am trying to update the main form with each record in the subform. I have two tables Invoice and Payment table. The main form has the payment details which I need to update for each invoice selectedon the subform. EG Invoice Table (SubForm) Ref no , Inv No , Amt 1 , 101 , 10.00 2 , 102 , 20.00 etc Payment Table Feilds (Main Form)
0
8851
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...
0
8747
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...
0
8627
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...
0
7356
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
5649
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
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
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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.