New Records replicate the value of the previous record

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

Guest

I am opening a continuous form that is linked to a query that is only showing
records with a certain [TransID] value (and it is a long integer number).

There could be 1 or multiple records (but never 0) and each one will always
have the same transid value (each time this form is opened it could listing
records based on a different transID value).

What I need to have happen is when a user opens the list and wants to create
a new record in that list of specific transID's, the new record has to
automatically take the transID value of all of the rest of the records in
that form at that time.
 
Hi.

First, set a Reference to the DAO Object Library if your database doesn't
already have this library referenced. Then, in your form's OnCurrent( )
event, try:

Private Sub Form_Current()

On Error GoTo ErrHandler

Dim recSet As DAO.Recordset

Set recSet = Me.RecordsetClone
recSet.MoveFirst

If (Me.NewRecord) Then
Me!txtTransID.Value = recSet.Fields("TransID").Value
End If

CleanUp:

Set recSet = Nothing

Exit Sub

ErrHandler:

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

.. . . where TransID is the name of the field that needs to be copied from
the other records, and txtTransID is the name of the text box bound to the
TransID field.

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.
 
BLTibbs said:
I am opening a continuous form that is linked to a query that is only showing
records with a certain [TransID] value (and it is a long integer number).

There could be 1 or multiple records (but never 0) and each one will always
have the same transid value (each time this form is opened it could listing
records based on a different transID value).

What I need to have happen is when a user opens the list and wants to create
a new record in that list of specific transID's, the new record has to
automatically take the transID value of all of the rest of the records in
that form at that time.


Check back to your original thread. I think you didn't
quite grasp the implications of my brief explanation
yesterday.
 
Back
Top