none
I want to automatically apply a discount in a specific record in a subform RRS feed

  • Question

  • Hi everyone,
    I have a form named "frmDétails commande" on which I have a subform named "sbfOrderDetails" and another subform to apply discount named "frmEscomptesItemCourant"

    On the main form I have a field that contains the ID of the sbfOrderDetails that I want to change... below is an image the is self explanatory and at the end the code that I have on the discount subform, an you help me automate this process of applying a discount on a specific record in a subform... (Note that if I enter manually the discount in the Escompte field, it works)

    Image:

    Here is the code on the OK button:

    Private Sub OK_Click()
    
    On Error GoTo Change_Err
    
    Dim dbs As dao.Database
    Dim rst As dao.Recordset
    
    Set dbs = CurrentDb()
    
        Set rst = dbs.OpenRecordset("Détails commande current record")
        
    With rst
        .Edit
        !Escompte = Me.txtDisplay.Caption
        .Update
    End With
        Forms![frmDétails commande].sbfOrderDetails.Requery
        Forms![frmDétails commande].[Total prix commande].Requery
        Forms![frmDétails commande].[Formulaire Sous-Totaux commande].Requery
    
    Me.txtDisplay.Caption = 0
    DoCmd.GoToControl "EscompteVisible"
    'Forms![frmDétails commande].[EntrezEscompteSeul].Form.Visible = False
    'Call cmdClear_Click
    
    CLoseRst:
    
        dbs.Close
        Set rst = Nothing
        Set dbs = Nothing
        
    Change_Err:
        If Err = 2110 Then
        Resume Next
        End If
        
    End Sub
    

    Thank you for your input

    Claude from Quebec, Canada


    Claude Larocque

    Saturday, July 29, 2017 6:42 AM

Answers

  • Could you instead just set the value directly on the subform, without involving the recordset:

    Forms![frmDétails commande].sbfOrderDetails.Form!Escompte = Me.txtDisplay.Caption
        Forms![frmDétails commande].[Total prix commande].Requery
        Forms![frmDétails commande].[Formulaire Sous-Totaux commande].Requery

    Also, if this is running in a Subform, and the OTHER Subform is on the same Parent form, you could do this instead:

    Me.Parent.sbfOrderDetails.Form!Escompte = Me.txtDisplay.Caption
    Me.Parent.[Total prix commande].Requery
    Me.Parent.[Formulaire Sous-Totaux commande].Requery


    -- Scott McDaniel, Microsoft Access MVP

    Saturday, July 29, 2017 10:40 AM

All replies

  • Could you instead just set the value directly on the subform, without involving the recordset:

    Forms![frmDétails commande].sbfOrderDetails.Form!Escompte = Me.txtDisplay.Caption
        Forms![frmDétails commande].[Total prix commande].Requery
        Forms![frmDétails commande].[Formulaire Sous-Totaux commande].Requery

    Also, if this is running in a Subform, and the OTHER Subform is on the same Parent form, you could do this instead:

    Me.Parent.sbfOrderDetails.Form!Escompte = Me.txtDisplay.Caption
    Me.Parent.[Total prix commande].Requery
    Me.Parent.[Formulaire Sous-Totaux commande].Requery


    -- Scott McDaniel, Microsoft Access MVP

    Saturday, July 29, 2017 10:40 AM
  • Thanks Scott,

    Sometimes we search for complicated solutions when its easy, amazing :)

    It works at first try

    Claude


    Claude Larocque

    Monday, July 31, 2017 10:55 AM