Wrox Programmer Forums
|
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
 
Old January 3rd, 2005, 08:04 PM
Registered User
 
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

 
Old January 6th, 2005, 01:39 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

For access you could check: http://mvps.org/access/

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old March 10th, 2005, 03:19 PM
Registered User
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old March 10th, 2005, 08:01 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
 
Old March 11th, 2005, 06:31 PM
Registered User
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old March 16th, 2005, 04:12 PM
Registered User
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>

 
Old March 20th, 2005, 07:23 AM
Authorized User
 
Join Date: Mar 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding records to db djobes31770 VB Databases Basics 3 November 27th, 2007 09:27 AM
Adding Records with VBA rohit_ghosh Access VBA 7 June 22nd, 2007 05:05 AM
adding multiple records Vince_421 VB Databases Basics 4 February 28th, 2007 07:22 AM
adding records sinner Classic ASP Databases 5 February 25th, 2004 06:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.