By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,948 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,948 IT Pros & Developers. It's quick & easy.

macro adds new records and fill field

P: 2
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.
Apr 2 '14 #1
Share this Question
Share on Google+
2 Replies


zmbd
Expert Mod 5K+
P: 5,397
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.
Apr 2 '14 #2

P: 2
I will do my homework better
Apr 2 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.