Open 2nd form in Add Mode with a value taken from 1st form

  • Thread starter Thread starter NKA
  • Start date Start date
N

NKA

Hi all,

I have trawled through the forums looking for a direct answer to this but to
no avail.

Here's my problem:

On frmTask (Form 1) I have a field called TaskID. When user clicks the
button (cmdNote), I want to open frmIssue (Form 2) in Add Mode but with
TaskID already populated in the record.

Can anyone assist with the correct code for this please? I am using Access
2007 and not particularly experienced with coding (I do have some basic
knowledge).

Your assistance is appreciated.
 
The easiest way to do this is to set the "On Click" event of the control
"cmdNote" to embedded macro. Then set the action property to "openform" then
under arguments set the Action Arguments to:

Form Name: Name of Form to open
Data Mode: Add
Where condition: ="[TaskID]=" & Nz([TaskID],0)
 
Thanks for the quick response FrozenJackal.

I have set the button as you suggested and all looks to be working fine.
However. I am not seeing the TaskID on the form. The form definitely opens
in Add mode (the ID field shows as (New)). I know Access 2007 has it's own
quirks.. this must be another one of them! Any other suggestions how I can
show the TaskID in the TaskID field for the new record?

Utimately, once the 2nd form is open and the TaskID populated, I want to
disable that field to the user.
 
Thanks for the quick response FrozenJackal.

I have set the button as you suggested and all looks to be working fine.
However. I am not seeing the TaskID on the form. The form definitely opens
in Add mode (the ID field shows as (New)). I know Access 2007 has it's own
quirks.. this must be another one of them! Any other suggestions how I can
show the TaskID in the TaskID field for the new record?

Utimately, once the 2nd form is open and the TaskID populated, I want to
disable that field to the user.

Any reason that you're using a (fairly complex to implement) popup form rather
than a (very simple) Subform, which takes care of this automatically?

If so, you will need to pass the TaskID in the OpenArgs argument of the
Openform method; then in the form's Open event, set the DefaultValue property
of the TaskID control to the passed value.
 
Hi John,

No particular reason other than the 2nd form can also be opened from a
different 1st form.

If I try to explain here what it is I am doing - maybe you have a more
slicker approach (if it's subforms then fine - I am open to any suggestions
that make my life easier!).

So, I have Tasks and I have Servers - both of which can have notes/issues.
I have created one single notes/issues table to store both.

The thinking was that the user could click a button to be directed to the
notes form with the linking field data displayed but disabled. If the note
has been generated from a Task, the TaskID would show with ServerID not
visible and if the note has been generated from the Server, then ServerID
details displayed....

I was thinking this would be minimum coding - am I on the wrong track?
 
Hello again John,

I took your advice and tried the subform route - success! Thank you so much
for pointing me in that direction - you know sometimes - you just get
wall-eyed and don't see outside of them!

Many thanks
 
Back
Top