When I open the 'Vehicle Info Form' I am inside a record. That record
is
saved. I click the Add Maint Record button and it does open my Maint
Record
Entry form.
I want the Maint Record Entry form to open new but be linked to the
vehicle
record I am currently open on.
I have entered the code you said on the Maint Record Entry form under
the
as
an event procedure On Load and it is still opening to 'NEW' ID on the
Vehicle
table. It is not linking to the vehicle on the main form.
:
First there must be a record in the main form to link to. That means
you
need to create a record and save it. Save it in the first code line of
the
open second form code. Do not make any other changes to controls in
the
main
form other than the code in the button to open the second form.
The open form VBA code should read like (using macros does not allow
any
error handling, and will run slower, and I'm not even sure that you
can
do
this with a macro):
DoCmd.OpenForm "Maint Record Entry", , , "ID =" & Me.ID
Use the wizard to create the code from the button, then delete
anything
about stLinkCriteria and the DoCmd line and replace it with the line
above
The DefaultValue property of the ID textbox in "Maint Record Entry" is
an
expression which should read:
= [Forms]![Vehicle Info]![ID]
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
I changed the where condition of the button to "Add New Maint Record"
where
condition to [ID]=[Forms]![Vehicle Info]![Maint Record Entry]![ID]
in
the
On
Click Macro.
The Open Form action is Maint Record Entry, Form, ,
[ID]=[Forms]![Vehicle
Info]![Maint Record Entry]![ID], Add, Normal
On the Maint Record Entry form I put the Default value of the ID of
the
Vehicle Info 'Main Form' as [ID] =[Forms]![Vehicle Info]![ID]
When I click the button to add a new record, The Maint Record Entry
form
opens to NEW in both ID fields. It should be opening to the Vehicle
I
was
working on ID field. The two fields are ID field for the Maint
Record
and
ID field for the Vehicle.
If I add a entry Access tells me there is no record for the Vehicle.
:
The problem is:
The "Add Maintenance form" is not linking the information with
the
vehicle
I
am adding it to. In the ID field it has "####"
Make sure the width of the control is wide enough to display the
entire
ID
field.. A separate form is not linked you need to use code.
First set the default value of the ID link field to:
= Forms!Form1_Name!ID
so that new records will pick up the ID from the main form
(remember,
this
is the foreign key not a primary key in the second form).
Now you can either open it to a record, and if there is not, it
will
use
the
default:
DoCmd.OpenForm "Form2", , , "ID =" & Me.txtID
or straight to a New record:
DoCmd.OpenForm "Form2", , , , acFormAdd
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com