Updating Linked Form Data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a button which has a linked form filtered on "VendorID".

The results are just fine. However, when I add a new record on the linked
form, I want the "VendorID" field to default to the "linked" value.

Any ideas from the experts on how I can do this simply?

Thanks,
Leslie
 
Hi, Leslie.

If you don't have any code interfering with how the text box gets its
DefaultValue Property, then you could try assigning it to the text box during
the form's OnCurrent( ) event for the new record. Try:

Private Sub Form_Current()

On Error GoTo ErrHandler

If (Me.NewRecord) Then
Me!txtVendorID.Value = Me!txtVendorID.DefaultValue
End If

Exit Sub

ErrHandler:

MsgBox "Error in Form_Current( ) in " & Me.Name & _
" form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

.. . . where txtVendorID is the name of the text box bound to the VendorID
field. If you cannot use the DefaultValue Property, then if the form that
opened the current form is still open and the VendorID value is displayed on
that form, then try the following line of code in the form's OnCurrent( )
event instead:

Me!txtVendorID.Value =
Forms("frmMyForm").Controls("txtOrigVendorID").Value

.. . . where frmMyForm is the name of the other form and txtOrigVendorID is
the name of the text box displaying the VendorID on that form.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Leslie said:
I have a button which has a linked form filtered on "VendorID".

The results are just fine. However, when I add a new record on the linked
form, I want the "VendorID" field to default to the "linked" value.


Several ways to approach this, depending on how the form's
interact with each other. Is the "linked form" opened by
the form with the button? Or, is the linked form always
open?

One way that might be ok regardless of that, but requires
the VendorID to **always** come from the same form, is to
have the linked form get the default from the button form in
the linked form's BeforeUpdate event:

Me.VendorID = Forms!buttonform.controlwithlinkedvalue
 
Hi Gunny,

You've helped me once again! You're the best! I couldn't use the default
value function, I got error 438 "Object doesn't support this property or
method". But I was successfully able to extract the data from the
"frmMyForm" (in your example).

Thank you Gunny, you are a great help.

Cheers,
Leslie
 
Marshall,

Between your and Gunny's responses, I was successfully able to get the
VendorID field updated for my new records. I left the logic on the "On
Current" event per Gunny's response, instead of putting the logic on the
"Before Update" of the linked form. Not sure what the difference would be.

Thanks again!
Leslie
 
The diference is that doing it in the Current event dirties
the record before the user does anything. If the user
should decide not to create the new record, you would still
create an otherwise blank record (ubless the user knows
enought to hit Esc the required number of times).

Using the Form's BeforeUpdate event, guarantees that the
user want to save a the new record when you add the linking
value to it.
 
Thanks Marshall,

I will move the logic from On Current to Before Update. Thank you for the
clarification.

Regards,
Leslie

Marshall Barton said:
The diference is that doing it in the Current event dirties
the record before the user does anything. If the user
should decide not to create the new record, you would still
create an otherwise blank record (ubless the user knows
enought to hit Esc the required number of times).

Using the Form's BeforeUpdate event, guarantees that the
user want to save a the new record when you add the linking
value to it.
--
Marsh
MVP [MS Access]


Between your and Gunny's responses, I was successfully able to get the
VendorID field updated for my new records. I left the logic on the "On
Current" event per Gunny's response, instead of putting the logic on the
"Before Update" of the linked form. Not sure what the difference would be.
 

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

Back
Top