2014-11-05 71 views
0

嗨,我通過recordsetclone方法添加新的記錄到子表單。問題是新的記錄出現在表格中,但保存它不會出現在表格中。如果手動添加此記錄,一切正常。如果記錄添加手動更新部分的if語句正常工作。記錄集添加新記錄到子表單中,但保存沒有添加到表

這是我的代碼。

'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 
+0

也許你需要發出你的子窗體的'Refresh'或'Requery'?記錄是否添加到基礎表? – 2014-11-05 16:12:18

+0

如果我DoCmd.Requery它只是不出現在子窗體中。它就好像AddNew不起作用,但編輯更新正常工作。 – 2014-11-05 16:21:55

回答

0

問題是我已經鏈接到OrderID的子表單查詢,並忘記添加它,所以額外的字段修復它。所以它增加了新的字段,但沒有OrderID,這就是爲什麼它沒有出現在子表單中,因爲它被過濾掉了。

'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 
相關問題