I am trying to duplicate a form and subform. Each record in the form is identiefied by a BookingID which is an autonumber.
When I run the following duplicate command, a message appears saying 'You tried to assign the Null value to a variable that
is not a Variant data type.' It is a Runtime error 3162. This form is a booking form and the subform contains food items
for each booking.
Private Sub DuplicateARecord_Click()
'On Error GoTo Err_Handler
'Purpose: Duplicate the main form record and related records in the subform.
Dim strSql As String 'SQL statement.
Dim lngID As Long 'Primary key value of the new record.
'Save and edits first
If Me.Dirty Then
Me.Dirty = False
'Make sure there is a record to duplicate.
If Me.NewRecord Then
MsgBox "Select the record to duplicate."
'Duplicate the main record: add to form's clone.
!BookingID = Me.BookingID
!SerialNo = Me.SerialNo
!NoOfBookingPerRequistionNo2 = Me.NoOfBookingPerRequistionNo2
!NameOfHost = Me.NameOfHost
!TrustOrNonTrust = Me.TrustOrNonTrust
!Department = Me.Department
!ContactTelephone = Me.ContactTelephone
!ContactMobile = Me.ContactMobile
!ContactFax = Me.ContactFax
!DateOfRequest = Me.DateOfRequest
!DateOfFunction = Me.DateOfFunction
!TimeRequiredStart = Me.TimeRequiredStart
!TimeRequiredEnd = Me.TimeRequiredEnd
!Venue = Me.Venue
!ReasonForBooking = Me.ReasonForBooking
!NoOfGuests = Me.NoOfGuests
!StandingOrder = Me.StandingOrder
!Comments = Me.Comments
!BookingReceivedBy = Me.BookingReceivedBy
'Save the primary key value, to use as the foreign key for the related records.
.Bookmark = .LastModified
lngID = !BookingID
'Duplicate the related records: append query.
If Me.[MenuSelection].Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO [MenuSelected] ( BookingID, ItemID, Itemname, NumberofitemID, [Trust:Itemcost],
SubTrustcost, [NonTrust:Itemcost], SubNonTrustcost, Itemcomment, PriceComment ) " & _
"SELECT " & lngID & " As NewID, ItemID, Itemname, NumberofitemID, [Trust:Itemcost], SubTrustcost,
[NonTrust:Itemcost], SubNonTrustcost, Itemcomment, PriceComment ) " & _
"FROM [MenuSelected] WHERE BookingID = " & Me.BookingID & ";"
DBEngine(0)(0).Execute strSql, dbFailOnError
MsgBox "Main record duplicated, but there were no related records."
'Display the new duplicate.
Me.Bookmark = .LastModified
MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdDupe_Click"
I am no programmer as I found the coding on internet and substituted the necessary fields. Is there a way round this