Re: How to link forms with command button

Tech-Archive recommends: Fix windows errors by optimizing your registry



"George McDonald" <GeorgeMcDonald@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:CABD3D33-63AA-4BF0-AB76-FA1918648FE1@xxxxxxxxxxxxxxxx

I have tried your suggestion and also Fredg with no luck. Can you help by
being more specific on where I would insert either code.

I have entered your
code on the 'on enter' of the command button, this gives me a syntax,
compile
error.

Ok, now why would we put the code in a different event, and different place
then suggested?

We can't just throw things at the wall, and hope they will stick like mud!!!
(computers don't work that way!!).

So, lets grab a cup a tea, take a step back, and think through what we are
doing:

We want to open a form to edit some related data. So, your first code of:

stDocName = "Add tech rep"

stLinkCriteria = "[ID work details]=" & Me![ID Work details]
DoCmd.OpenForm stDocName, , , stLinkCriteria

The above code should open our form. The stLinkCriteria will RESTRICT THIS
FORM to the reocrds that belong (are related) to our first (main) form. Up
to this point, if you not added any reocords in "add tech rep", then when it
the form opens, it likey will not have any rocords in it. You should at this
point be able to START entering a new reocrd. (if there is exsting reocrds,
then you can view them).

So, what we are trying to accomplish here is that when you INSERT (or shall
we say add) a new reocrd, we must set up the value of the field [id work
details].

So, my suggestion was:
<quote>

Just put the following code in the forms before insert event:


me![Id word details] = forms!PrevousFormNameGoesHere![id word details]

Note carefully the above suggestion. Again, if we think this through, we
taking about *inserting* a new record. So, we are obviously talking about
the forms "before insert event", and that form is our "add tech rep"
form..right? (what other form would *likey* make sense here?)

So, the above code is to be entered on the "add tech rep" forms "before
insert" event.

also, since I am not a mind reader, I have:

me![Id word details] = forms!PrevousFormNameGoesHere![id word details]

You obviously have to replace !PrevousFormNameGoesHere with the name of the
main form (the one with your button code).

Also, make careful note of the other suggestions here (such as make sure you
did not accidentally set the "data entry" of this form to add child records
(add tech rep) = yes, as this will not allow you to review exiting records
(but, on the other hand, you *might* want this behaviour)

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@xxxxxxx


.


Quantcast