On one of my forms, I want to add a "Duplicate" button, so that it will duplicate some of the contents of the current record into a new record. I know how to do this with information that is contained in text boxes. However, one field on my form is an attachment field. I can't figure out how to copy whatever is in the attachment field into a variable and then put it in the new record.
Here's the code I have written to move the rest of the data in the record.
Code:
Option Compare Database
Option Explicit
Private Type BoxRentalInfo
TrueFalse As Boolean
Amount As Single
AcctCode As String
DayOrWeek As String
Notes As String
Inventory As String
End Type
Private Sub DuplicateButton_Click()
Dim EmployeeID As Integer
Dim PositionID As Integer
Dim PositionAcctCode As String
Dim PositionCoveredByUnion As String
Dim Rate As Single
Dim Guarantee As Single
Dim StartDate As Date
Dim Term As String
Dim TopOfStartForm As String
Dim BoxRental As BoxRentalInfo
If Me.Dirty Then Me.Dirty = False
EmployeeID = Me.EmployeeID
PositionID = Me.PositionID
PositionAcctCode = Me.PositionAcctCode
PositionCoveredByUnion = Me.PositionCoveredByUnion
Rate = Me.Rate
Guarantee = Me.Guarantee
StartDate = Me.StartDate
Term = Me.Term
TopOfStartForm = Me.StartFormCheckBox
If Me.List45 = "Yes" Then
BoxRental.TrueFalse = True
BoxRental.Amount = Me.BoxRentalAmount
BoxRental.AcctCode = Me.BoxRentalAcctCode
BoxRental.DayOrWeek = Me.BoxRentalDayWeek
BoxRental.Notes = Me.BoxRentalNotes
BoxRental.Inventory = Me.BoxRentalInventory
Else
BoxRental.TrueFalse = False
End If
'this creates the new record
DoCmd.GoToRecord , , acNewRec
'this copies the information into the new record
Me.EmployeeID = EmployeeID
Me.PositionID = PositionID
Me.PositionAcctCode = PositionAcctCode
Me.PositionCoveredByUnion = PositionCoveredByUnion
Me.Rate = Rate
Me.Guarantee = Guarantee
Me.StartDate = StartDate
Me.Term = Term
Me.StartFormCheckBox = TopOfStartForm
If BoxRental.TrueFalse = True Then
Me.BoxRentalYesNo = "Yes"
Me.BoxRentalAmount = BoxRental.Amount
Me.BoxRentalAcctCode = BoxRental.AcctCode
Me.BoxRentalDayWeek = BoxRental.DayOrWeek
Me.BoxRentalNotes = BoxRental.Notes
Me.BoxRentalInventory = BoxRental.Inventory
Else
Me.BoxRentalYesNo = "No"
End If
If Me.Dirty Then Me.Dirty = False
End Sub
Anyone know the syntax I would use to copy whatever data is in the attachment field into the new record?