473,467 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How copy date from main form to subform?

4 New Member
Greetings!

I have a table with the following fields:

TransactionID
TransactionDate
TransactionType
TransactionDetails
TransactionAccount
TransactionDeposit
TransactionWithdrawal

I created a main form called "Transfer Voucher" (The fields are: TransactionDate; TransactionType; TransactionDetails; TransactionAccount and TransactionWithdrawal) and included a sub-form called "Replenish" (The fields are: TransactionDate; TransactionType; TransactionDetails; TransactionAccount and TransactionDeposit). My primary objective create two transactions in one form - one for the withdrawal of amount from one account and another to deposit the same amount to another account. I was able to attain that.

To simplify the entry of records I want copy the TransactionDate and TransactionDetails in the main form to the TransactionDate and TransactionDetails in the sub-form. To do that I made an after update command in TransactionDate of the main form, as follows:

= [TransactionDate] = Forms![Replenish]![TransactionDate]

I did the same thing with TransactionDetails. When I tested the form, it indeed created two transactions (with different IDs) except that the Date and Details on the records from the sub-form were blank.

What can I do to automatically populate those common fields?

Thank you in advance.

Melo
Sep 26 '10 #1
8 8222
slenish
283 Contributor
Hello Melo,

First let me throw out this question for you...is the subform already open or does it open on a button click?

What you want to do is put the function you are trying to use in the subform either in the FormOpen function or FormGotFocus function. Depending on the answer to my first questions.

Do something like this
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.  
  3. Me.TextBox1 = [Forms]![MainForm]![TransactionDate]
  4. Me.TextBox2 = [Forms]![MainForm]![TransactionDetails]
  5.  
  6. End Sub
  7.  
  8.  
Sep 27 '10 #2
Hi Slenish,

Thank you very much for your help.

I am a bit confused, with your question as to whether my sub-form is open.

What I did was to create the subform first with the said fields and saved it as "Replenish". Then I created the main form and in the toolbox used the insert subform function. Then I saved the main form as "Transfer Voucher". When I open the Transfer Voucher form, I can already see that the subform is also open (meaning I can manually input the records in the fields). Does it mean that the subform is already open? I asked this question because I used a similar code but I got an error report that it cannot find "Replenish" and asked if it was open. Kindly enlighten me on this.

I am new at Access and I am not familiar with FormOpen and FormGotFocus functions. Where can I find them?

Kind regards

Melo
Sep 28 '10 #3
Melo3
4 New Member
Hi Slenish,

Thank you very much for your help.

I am a bit confused, with your question as to whether my sub-form is open.

What I did was to create the subform first with the said fields and saved it as "Replenish". Then I created the main form and in the toolbox used the insert subform function. Then I saved the main form as "Transfer Voucher". When I open the Transfer Voucher form, I can already see that the subform is also open (meaning I can manually input the records in the fields). Does it mean that the subform is already open? I asked this question because I used a similar code but I got an error report that it cannot find "Replenish" and asked if it was open. Kindly enlighten me on this.

I am new at Access and I am not familiar with FormOpen and FormGotFocus functions. Where can I find them?

Kind regards

Melo
Sep 28 '10 #4
Melo3
4 New Member
Hi Slenish,

Thank you for your patience.

I tried what you suggested and I entered the following code:

Private Sub TransactionAccount_AfterUpdate()

Me!TransactionDate = Me![Replenish].Form!TransactionDate.Value
Me!TransactionDetails = Me![Replenish].Form!TransactionDetails.Value

End Sub

Despite the code, the date and details were not copied. I don't know what was wrong?

Thanks

Melo
Sep 28 '10 #5
Harry38
2 New Member
@slenish
Hi Slenish,
I used yr code in my mainform/subform: if the name/address in the Mainform doesn't yet exist in the tbl in my subform; I push a button and the fields of the mainform are copied to the subform. It works excellent, except when the field in the MainForm is Null. How to ignore the fields that are Null.
Could you help me here.
Thanks - Harry

The code under the button:
Expand|Select|Wrap|Line Numbers
  1. Me.Voornaam = [Forms]![InvoerDownloads2]![Voornaam]
  2. Me.Adres = [Forms]![InvoerDownloads2]![Straat]
  3. Me.Aanhef = [Forms]![InvoerDownloads2]![Aanh]
  4. Me.Voorletters = [Forms]![InvoerDownloads2]![Voorletters]
  5. Me.Voorv = [Forms]![InvoerDownloads2]![Tussenvoegsels]
  6. Me.Adres = [Forms]![InvoerDownloads2]![Straat]
  7. Me.Postcode = [Forms]![InvoerDownloads2]![Postcode]
  8. Me.Woonplaats = [Forms]![InvoerDownloads2]![Woonplaats]
Apr 29 '14 #6
slenish
283 Contributor
Hi Harry,
Feels like I'm coming out of retirement to answer this one, haha. If I'm understanding the question correctly it sounds like you will want to use an IF statement or a Case statement to help catch a Null value. You could try something like...

Expand|Select|Wrap|Line Numbers
  1. If forms!mainform!text1 not is null then
  2.      Me.text1= forms!mainform!text1
  3. End if
  4.  
I'm trying to recall this from memory so I haven't tested the above code to make sure that's 100% right. If it doesn't work let me know.

Take care,
Slenish
Apr 29 '14 #7
jimatqsi
1,271 Recognized Expert Top Contributor
Or just use the NZ function. NZ(forms!mainform!text1) will not return an error even if the value is NULL.
Expand|Select|Wrap|Line Numbers
  1. Me.Voornaam = [Forms]![InvoerDownloads2]![Voornaam]
should be
Expand|Select|Wrap|Line Numbers
  1. Me.Voornaam = nz([Forms]![InvoerDownloads2]![Voornaam])
Jim
Apr 29 '14 #8
zmbd
5,501 Recognized Expert Moderator Expert
@Harry38:
1) You're actually very lucky that Slenish was still around to help with your question. In fact, if Slenish had not been so kind as to answer, your post most likly would have been removed because you've technically hijacked this thread. In the future, please create a new thread including a link to the original for context/reference if needed.

2) Please use the [CODE/] formatting button in the toolbar to format you posted code or tables. I realize that several posts in this thread do not have this formatting. At the time that may not have been a requirement; however, it is a requirement for all newer posts.

3) This thread appears to deal with a database that is not properly normalized as one does not normally store the same information in more than one table. If you are doing so, then please reconsider the design of your appliction.
Apr 29 '14 #9

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

Similar topics

9
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...
1
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...
2
by: Claude | last post by:
Let' say we have an application for a production facility running 24/7 broken into 3 shifts 6-2,2-10,10-6 each production report date contains 3 shifts as above in each shift there can be from...
3
by: PerryC | last post by:
I have a Main Form, then a subform. There is a date field in the Subform that I want to be able to click on it, and a VBCalendar popup in the main form for me to choose a date (I don't want it on...
0
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...
4
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...
0
by: nospam | last post by:
I have a main form that has 3 fields. They are all locked fields, only to show the user the "person" record that they are looking at. They update to subforms on a tab. The first subform is...
4
by: Mclaren | last post by:
Hi I have a main single record form that has a date field on it pupulated from primary table, i have subform (datasheet view) which is populated from the many table. the subform has a field that...
3
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!
3
by: informankur | last post by:
Hi All, I am trying to create a form for updating values. I have a Table - ASP with Date, Product, Q1,Q2,Q3,Q4 fields. I have a Form ASP_Main with "Date" field for filtering by the date selected....
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
1
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...
0
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,...
0
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...
0
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...
0
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...

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.