macro adds new records and fill field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bresca
    New Member
    • Apr 2014
    • 2

    macro adds new records and fill field

    how can i by clicking a command button to add records in a subform and get filled with a certain value?
    Eg: Click cmdToevoegen> adds 3 new records in subform with the following values​​: Value1 , value2 and value3.
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    bresca:

    We need to clear up the terminology:
    Access has two programing languages.
    1) Macro - best avoided unless makeing a sharpoint publishable application
    2) VBA - what most of us use to automate tasks such as you suggest in your post.

    Next:
    subform : although the methods to accomplish what you want are simular, we need to make sure that you mean subform and not a form in general. That is to say, you have a parent form and within that form you have a second related form (subform).

    Finally:
    We need to understand from where the values to enter into the new record will be obtained.

    The general format for the code will be:
    Insert the command button into the form
    Cancel any wizards
    Open the properties of the command button.
    Preferably change the control name to something usefull avoiding reserved words and tokens.
    In the events tab, on click event, button [...], select code not macro.
    In the code
    There are several methods to add the record and this will depend upon your reply as to how the values are obtained as the easiest method.
    Most assured method is to open a DAO record set on the table where you need to save the data
    Using the add.new method create the record and save/update
    close the record set
    force the subform to requery.

    Please understand, we do not normally write code. If you will write out your code, follow the basic troubleshooting steps found here: > Before Posting (VBA or SQL) Code and then post back your code with specfic details as to what it isn't doing and what it should along with any error messages... we can help from there.

    Comment

    • bresca
      New Member
      • Apr 2014
      • 2

      #3
      I will do my homework better

      Comment

      Working...