add form not passing value

S

sue gray

I have a form that calls a subform. On the subform I have two command
buttons, one to view a form (it works fine) and one to add a new form.

I've tried to add the form from both an event and a macro. Both ways I have
the same problem. I have a clientid field that I want it to pick up from
either the main form or the subform, but I can't figure it out.

Thanks in advance
 
J

John W. Vinson

I have a form that calls a subform.

By "calls" do you mean that you have VBA code or a Macro that *opens a
separate form*? Or do you actually have a Subform?
On the subform I have two command
buttons, one to view a form (it works fine) and one to add a new form.

Again: do you want to create a new Access Form object - or do you want to move
to a new record?
I've tried to add the form from both an event and a macro. Both ways I have
the same problem. I have a clientid field that I want it to pick up from
either the main form or the subform, but I can't figure it out.

If you have the second form in a Subform control on the main form, just set
the Master Link Field and the Child Link Field to the ClientID. No code is
needed at all.

If you're opening a separate form then *it is not a Subform*. It's a form in
its own right. What do you want to do with the ClientID when you open the
form?

John W. Vinson [MVP]
 
S

sue gray

Sorry for the confusion. I'm somewhat new at this and my terminology is not
correct. I have a subform (which is working fine). From the subform I want
to open an existing form and add a new record to that form.
If you're opening a separate form then *it is not a Subform*. It's a form in
its own right. What do you want to do with the ClientID when you open the
form?

I guess that is what I'm trying to do. I'm opening a form in its own right
from a subform. I want clientid passed from the subfrom to the newform.

I hope this is clearer.

Thanks again.
 
J

John W. Vinson

Sorry for the confusion. I'm somewhat new at this and my terminology is not
correct. I have a subform (which is working fine). From the subform I want
to open an existing form and add a new record to that form.


I guess that is what I'm trying to do. I'm opening a form in its own right
from a subform. I want clientid passed from the subfrom to the newform.

I'm still not completely clear on what you're doing and why.

You have a main form, FormA. On that form you have a subform, FormB.

Somewhere on FormB (or maybe it's on FormA??) you have a control, let's
speculate that it's called cboClientID, bound to the ClientID field.

You want to click a button on the subform B and have a third form, FormC, pop
up - and you want to "pass" the ClientID to it.

What is Form C going to do with that client ID? Do you want it to open to that
client's existing record? If so, use the WhereCondition argument of the
OpenForm method:

DoCmd.OpenForm "FormC", WhereCondition:="[ClientID] = " & Me.cboClientID

Or do you want FormC to create a new record adding ClientID? If so, use the
OpenArgs argument of the OpenForm method to pass the value of the clientID,
and then put code in FormC's Open event to set the DefaultValue property of a
control:

DoCmd.OpenForm "FormC", OpenArgs:= Me.cboClientID

....

Private Function Form_Open(Cancel as Integer)
If Me.OpenArgs & "" <> "" Then ' was an ID passed?
Me.cboClientID.DefaultValue = Chr(34) & Me.OpenArgs & Chr(34)
End If
End Sub

John W. Vinson [MVP]
 
Top