Recordset adds new record into sub form but on save nothing added to table

asol

New member
Local time
Today, 21:42
Joined
Oct 1, 2014
Messages
8
Hi I am adding new record into subform via recordsetclone method. The problem is that record is added but on save it does not appear in the table. If add this record manual using subform everything works. When record added manually update of the record works fine.

here is my code.

Code:
'Add Wastage value to flooring area section
Private Sub Wastage_AfterUpdate()
    Dim rsFlArea As DAO.Recordset
    Dim Wastage As Double
    Dim Item As String
    Set rsFlArea = Me.OrderFloorAreaEdit.Form.RecordsetClone
    'Caluate Wastage amount based on the percentage in parent form
    Wastage = Format((Me.FloorMeterage.Value * Me.Wastage.Value), "#,##0.00")
    
    'Check if it has been already added if not than add - note 12 is ID of floor area
    rsFlArea.FindFirst "[Item] LIKE '12'"
    If rsFlArea.NoMatch Then
            rsFlArea.AddNew
            rsFlArea!Item = 12
            rsFlArea!Units = Wastage
            rsFlArea!uPrice = Me.flPrice.Value
            rsFlArea.Update
        Else
        ' If value exist in recordset than update the value
        Do Until rsFlArea.EOF
            If rsFlArea!Item = 12 Then
                rsFlArea.Edit
                rsFlArea!Units = Format(((Me.FloorMeterage.Value - Nz(rsFlArea!Units, 0)) * Me.Wastage.Value), "#,##0.00")
                rsFlArea.Update
            End If
            rsFlArea.MoveNext
        Loop
    End If
    
    rsFlArea.Close
    Set rsFlArea = Nothing
End Sub
 
Last edited:
Not sure what you want to get.
Why not simply add the record to the table and requery the form to show last record
 
Not sure what you want to get.
Why not simply add the record to the table and requery the form to show last record

I need to add record to subform, and the value of that record depends on existing records in subform as well as values in parent form.
 
You dont add records to forms. You add records to tables.
Forms are representing a table or a query data.
 
You dont add records to forms. You add records to tables.
Forms are representing a table or a query data.

Mate I know what I am doing, and I also know that you dont add records to forms, if you do not have any solution for my problem than thanks for trying. There is no point of acting smart if you do not know the solution for the problem and start with demagogy.
 
You search for a string value in the FindFirst, but looking at you code it should be a number.
 
The problem was that I have linked the subform query to OrderID and forgot to add it so additional field fixed it. So it was adding new field but without OrderID thats why it did not show up in the subform as it was filtered out.

Code:
'Add Wastage value to flooring area section
Private Sub Wastage_AfterUpdate()
    Dim rsFlArea As DAO.Recordset
    Dim Wastage As Double
    Dim Item As String
    Set rsFlArea = Me.OrderFloorAreaEdit.Form.RecordsetClone
    'Caluate Wastage amount based on the percentage in parent form
    Wastage = Format((Me.FloorMeterage.Value * Me.Wastage.Value), "#,##0.00")

    'Check if it has been already added if not than add - note 12 is ID of floor area
    rsFlArea.FindFirst "[Item] LIKE '12'"
    If rsFlArea.NoMatch Then
            rsFlArea.AddNew
            rsFlArea!OrderID = Me.OrderID.Value
            rsFlArea!Item = 12
            rsFlArea!Units = Wastage
            rsFlArea!uPrice = Me.flPrice.Value
            rsFlArea.Update
        Else
        ' If value exist in recordset than update the value
        Do Until rsFlArea.EOF
            If rsFlArea!Item = 12 Then
                rsFlArea.Edit
                rsFlArea!Units = Format(((Me.FloorMeterage.Value - Nz(rsFlArea!Units, 0)) * Me.Wastage.Value), "#,##0.00")
                rsFlArea.Update
            End If
            rsFlArea.MoveNext
        Loop
    End If

    rsFlArea.Close
    Set rsFlArea = Nothing
End Sub
 

Users who are viewing this thread

Back
Top Bottom