Open a Form and copy a field into it (1 Viewer)

Malkim92

Registered User.
Local time
Today, 20:51
Joined
Jun 18, 2012
Messages
15
Hello everyone,

I'm new to this forum and I'm also new to MS access.

Im facing a problem with opening a new form from a form and setting two fields to equal two other fields from the original form.

I have Form A which includes FieldA and FieldB, and FormB which includes FieldC and FieldD.
Now here is the problem, I want to open FormB from FormA using a button and i want FieldA and FieldB to be copied to FieldC and FieldD in that form.

I found a way to copy one field only by using this on on Click command on the button, which is;
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "FormB", , , , , , Me.FieldC

and by using an on Load command on FormB, which is;
If Me.OpenArgs <> "" Then
Me.FieldC = OpenArgs
End If

but i cant seem to be able to copy 2 fields instead of only 1.

Any help would be much appreciated.
 

RainLover

VIP From a land downunder
Local time
Tomorrow, 03:51
Joined
Jan 5, 2009
Messages
5,041
The approach could vary depending on what you are trying to do.

At first glance it appears that you are duplicating data which is not in keeping with best design principals. Namely Normalisation.

It would help if you explained more and please use proper names. A, B, C etc is difficult to help create a picture.
 

Malkim92

Registered User.
Local time
Today, 20:51
Joined
Jun 18, 2012
Messages
15
Ok basically, i have a two tables; Customer Information and Customer Purchases, and 2 forms based on that. The Customer Information form has 2 fields, Customer Name and Customer ID.

The second form has the same fields; Customer Name and Customer ID. What i want to do it that when i open the second form from the Customer Information form, it will automatically copy the Customer Name and ID. I cant use relationships since the second table doesn't have the name and ID as unique keys since i need to have duplicates so im using the forms to enter into both tables.
 

pr2-eugin

Super Moderator
Local time
Today, 18:51
Joined
Nov 30, 2011
Messages
8,494
Hello Malkim92, I have done something like that.. So I hope this is what you are looking for..
Code:
Private Sub CopyRecordsBtn_Click()

'   This method is used to add details of an existing customer to the 'Customer Purchases' table
'   As this is just an addition of already existing information, we obtain all information from
'   the current form i.e "Customer Information" form and assign them to the "Customer Purchases".

     DoCmd.OpenForm "Customer Purchases", acNormal
     DoCmd.GoToRecord , , acNewRec
     Forms!Customer Purchases![Customer ID].Value = Me.[Customer ID]
     Forms!Customer Purchases![Customer Name].Value = Me.[Customer Name]
End Sub
 
Last edited:

spikepl

Eledittingent Beliped
Local time
Today, 19:51
Joined
Nov 3, 2010
Messages
6,142
Do NOT proceed with the code pr2-eugin gave you. Your are off on a completely wrong path.

I cant use relationships since the second table doesn't have the name and ID as unique keys since i need to have duplicates so im using the forms to enter into both tables.
There is something rotten here. The normal way of doing this is:

tblCustomers
-------------
CustomerID
CustomerName

tblPurchases
-------------
PurchaseID
CustomerID
Other purchase data

What is the reason that you have your own style of tblPurchases? Whatever you do, do NOT duplicate data.

Also, do not use spaces in any names in Access - that will only lead into problems.

BTW: Google "database normalization", read and absorb the material and then do some online tutorial on Access table design before proceding with anything else.
 
Last edited:

Malkim92

Registered User.
Local time
Today, 20:51
Joined
Jun 18, 2012
Messages
15
I do have the Purchase ID, but i need the customer name with the Customer ID. I need that because I'm going to make a search form to find a customer purchase history by ID or by Name incase the person forgot the ID.
 

spikepl

Eledittingent Beliped
Local time
Today, 19:51
Joined
Nov 3, 2010
Messages
6,142
I have told you what you need to do. There is no immediate penalty for not taking my advice. Just extra work later, when you yourself realize that you must restructure your data and rewrite code. You are welcome to the long route. And after doing a tutorial on tables, do one on queries. Before you understand how queries tick you won't get far in any sensible way.
 

RainLover

VIP From a land downunder
Local time
Tomorrow, 03:51
Joined
Jan 5, 2009
Messages
5,041
Do you understand the use of a Form with a Sub Form.

This might be the approach you need. I believe that is the way I would do it.
 

Malkim92

Registered User.
Local time
Today, 20:51
Joined
Jun 18, 2012
Messages
15
Thanksfor the help, I followed spikepl's advice and I got it done.
 

RainLover

VIP From a land downunder
Local time
Tomorrow, 03:51
Joined
Jan 5, 2009
Messages
5,041
Spike

You have a lovely way with words. :D
 

pr2-eugin

Super Moderator
Local time
Today, 18:51
Joined
Nov 30, 2011
Messages
8,494
Thanks spikel.. I understand what you mean by not having to duplicate data.. I am not here to justify, but my requierment was quiet different.. Mine does not store the values.. but just copies the content of the Customer form to the Mail form (unbound) so that they can use the information to mail.. I read the post wrong.. so I thought it was something similar.. BUT I AM WRONG..
Spike

You have a lovely way with words. :D

Am sorry Malkim92 if this has caused you any trouble.. I am still kinda learning.. I hope you get good guidance form far better experts like spikepl and RainLover
 

Malkim92

Registered User.
Local time
Today, 20:51
Joined
Jun 18, 2012
Messages
15
Its not a big deal pr2-eugin, no harm happened :).
Im still a noob at this myself, but thanks anyways.
 

Users who are viewing this thread

Top Bottom