Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 5th, 2014, 09:03 AM
Registered User
 
Join Date: Nov 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Recordset adds new record into sub form but on save nothing added to table

Hi. I am adding new record into subform via recordsetclone method. The problem is that new record appears in the form but on save it does not appear in the table. If add this record manually everything works. If record added manually update section of if statement 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 by Andrius; November 5th, 2014 at 12:28 PM..
 
Old November 5th, 2014, 12:36 PM
Registered User
 
Join Date: Nov 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem was that I have linked the subform query to OrderID and forgot to add it so additional field fixed it

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Record to table from form AlForum29 Access VBA 2 January 2nd, 2013 09:46 PM
Populate form fields if record exists in table RobertIngles Access VBA 1 February 18th, 2011 05:21 AM
F5 (Refresh) adds a new record after postback krainov BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 November 20th, 2007 10:10 AM
Create Dynamic Form; end-user adds/drops columns pkaptein1 Access 6 February 15th, 2006 03:32 AM
Save simple record via web form t sql database kbarsi VB Databases Basics 1 January 30th, 2005 11:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.