Full Version: Populate Certain Form Fields With Previous Record.
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Hi UA,
I have a form (loadhaulbav) that enters data into a table (tblload).
In order to streamline data captunring I want to add a button or checkbox to populate certain fields
from the previous record.
I have started with a select case option on the checkmark:
What I am having a hard time with is howto use the dlookup for the table and field for the last record enterd.
Private Sub chkreloadstep1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Me.chkreloadstep1.Value
      Case Is = True
        MsgBox "CASE TRUE"
      Case Is = False
        MsgBox "CASE FALSE"
      End Select
End Sub

Thank you for your time and help,
check this previous thread Module To Carry Values Over From Previous Form Entry., Office 2010
Here is a way to duplicate the record in the main form along with any subform records. You could just leave out the part of the code that deals with the subform records:
ssentially it would go something like this (in a command button Click event, for instance):

With Me.RecordsetClone
   'Add the fields that need to be the same in the new record.  These are sample fields, so change the names as needed.
    !CustomerID = Me.CustomerID
    !EmployeeID = Me.EmployeeID
    !OrderDate = Date
   'etc for other fields.
  'Display the new duplicate.
  Me.Bookmark = .LastModified
End With

There are other ways to go about this. For instance, the link shows INSERT SQL for adding the subform records. The same general approach could be used to add the main form records.
The command button wizard can set up code to duplicate a record. However, in Access 2003 (and in 2000, I think) this uses DoMenuItem commands, and duplicates the entire record. It is possible to use acCmdSelectRecord, acCmdCopy, and acCmdPasteAppend in succession to accomplish copying the entire record, but I think you will be glad, eventually if not right away, to have more control than that method allows.
Hi arnelgp,
Thank you for that - I should have mentioned that I am running access 2010.
Also the fields on the form are combo boxes that are being populated with data from different tables :-)
I have implemented that code & Module but I get an compile error on the BeforeInsert Code:
"Expected variable or procedure, not module" here: Call CarryOver(Me, strMsg)
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim strMsg As String
        Call CarryOver(Me, strMsg)
        If strMsg <> vbNullString Then
            MsgBox strMsg, vbInformation
        End If
End Sub

Thank you,
Hi arnelgp,
I have copied the code from the attached .zip you amended - and it works beautifully !!
Thank you again for your time and help.
Hi BruceM,
Thank you for that, - I am already achieving what I need to do with arnelgp`s code....
I have not yet tried your code... seeing that the other alternative works good.
Thank you again for your help!
Kind regards,
Been out for a while.
You're welcome Bongazi.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.