copy data from one form to another by open button cmd

K

keith.loney

Hi,

I need to copy the primary key of one table to be in
another table this i am attempting to do by clicking a
open form button to open the second form
so far the code i have been playing with is like this

Dim stDocName As String
Dim StLinkCriteria As String

stDocName = "Frm:Contacts"
StLinkCriteria = "[unit_no] = " & "'" & Me![c_unit]
& "'"
DoCmd.OpenForm stDocName, , , StLinkCriteria


Any help appreciated
 
S

Steve Schapel

Keith,

The second form can't open at the record indicated, because there isn't
one yet... if I understand your purpose correctly. It seems to me that
you need more like this...

DoCmd.OpenForm "Contacts"
Forms!Contacts!Unit_No = Me.C_Unit

By the way, is your actual form named Frm:Contacts? It is not a good
idea at all to have a : as part of the name of a field or control or
database object such as a form, and I would recommend this be changed.
 
G

Gerald Stanley

The code you have written will work if the primary Key of
your first table is already in your second table and I am
surmising from your statement of the issue that that is not
the case. To pass the value to the sencond form, you will
need to use the OpenArgs parameter in the DoCmd.OpenForm
e.g.
DoCmd.OpenForm "Frm:Contacts", , , , , , Me![c_unit]

You will then need to add some logic in the second form to
process the value passed across. This is accessed by the
variable OpenArgs

Hope That Helps
Gerald Stanley MCSD
 
G

Guest

Steve,

Many thanks for this have renamed the form as suggested
and entered the code and it works really well
Many thanks for this as i was going slowly insane

Keith
-----Original Message-----
Keith,

The second form can't open at the record indicated, because there isn't
one yet... if I understand your purpose correctly. It seems to me that
you need more like this...

DoCmd.OpenForm "Contacts"
Forms!Contacts!Unit_No = Me.C_Unit

By the way, is your actual form named Frm:Contacts? It is not a good
idea at all to have a : as part of the name of a field or control or
database object such as a form, and I would recommend this be changed.

--
Steve Schapel, Microsoft Access MVP


Hi,

I need to copy the primary key of one table to be in
another table this i am attempting to do by clicking a
open form button to open the second form
so far the code i have been playing with is like this

Dim stDocName As String
Dim StLinkCriteria As String

stDocName = "Frm:Contacts"
StLinkCriteria = "[unit_no] = " & "'" & Me![c_unit]
& "'"
DoCmd.OpenForm stDocName, , , StLinkCriteria


Any help appreciated
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top