 |
| 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
|
|
|
|

January 3rd, 2005, 08:04 PM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Adding records to Tables
Hello All. I am very green with Access programming and I and trying my hand at something new here so please be patient.
Can someone oint me to a good example of writing multiple records to a single table using a single form?
My task is that I have one form that I enter data on and each "row" of data entered needs to be saved in a signle table.
I have Beginning Access 2000 VBA. Not finding much on this or better, I don't knwo how to look for a topic that would describe what I am trying to accomplish.
Thanks for any help.
Lance
|
|

March 10th, 2005, 03:19 PM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm doing somthing similar, but can't seem to find help on this site or the one linked above. I'm using a form to grab and parse a text file. This data is used to add multiple records to multiple tables. I know forms are typically linked to a single table, but will VBA let me add records to any table I like? If so, I'd really appriciate the beginnings of some code.
Thanks in advance.
|
|

March 10th, 2005, 08:01 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Keep in mind, that to do this your attitude must be âI have the control!â
[u]You</u> know the names of the controls on the form, so, when it is time to save the data, open a recordset, add a new record to it, and read the values of the controls for the first record into the fields of the recordset by using their names (eg, r!Addr = Me.txtbxAddr_1.text).
Once all the fields are filled, .Update the record, add another record, and read the controls for record number 2 into the fields of the recordset, again by using their names (eg, r!Addr = Me.txtbxAddr_2.text). The recordset fieldnames will be the same each time (but you will have created a new record), but the names of the controls from which the info is coming will be different, according to how you have named them.
Keep doing this until you have read all the controls.
You probably should add a test for each ârowâ to avoid adding any records for non-existent data.
|
|

March 11th, 2005, 06:31 PM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yeah, I know that much (though I'm still trying to iron out the details in code). My problem is that, according to my understanding, a given form can only be associated with a single table of data. I want to change two different tables with one button click. Am I misunderstanding how a recordset is opened?
I would really appriciate some example code if you've done anything like this before. I think that would help me better understand what's going on. Thanks again for any help you can provide.
|
|

March 16th, 2005, 04:12 PM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I found my own answer. If anyone else has a similar problem, this site helped me a lot to combine VBA and SQL: <http://www.fontstuff.com/access/acctut16.htm>
|
|

March 20th, 2005, 07:23 AM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I can help you with code, but you have to be specific. VBA help in createTabledef will give you lines for adding records to a table.
Multiple means to loop in the same procedure:
For...Next, Wile...Wend, Loop Until...End Loop.
|
|
 |