Connecting Tech Pros Worldwide Forums | Help | Site Map

Creating New Records in one Table from another table

Bec Bec is offline
Newbie
 
Join Date: Mar 2007
Posts: 1
#1: Mar 27 '07
Ok, here's my problem...... I have a contacts table which includes, ID, FirstName, LastName, Category, Region, Date of Birth, etc. Then i have a Personal Details Table which lists their home addresses and a business table that lists their business addresses.

The problem is.... some of our contacts have their home addresses as preferred mailing addresses, others have their business addresses. I have a yes/no field in the table that says "MailingAddress?". When this checkbox is ticked i want a new record to be created in a table "tbl_MailingAddress"

Any ideas would be much appreciated, and please be gentle....it's been a while since i used Access and VBA.

Thanks
Bec :-)

Newbie
 
Join Date: Jan 2007
Posts: 16
#2: Mar 27 '07

re: Creating New Records in one Table from another table


Quote:

Originally Posted by Bec

Ok, here's my problem...... I have a contacts table which includes, ID, FirstName, LastName, Category, Region, Date of Birth, etc. Then i have a Personal Details Table which lists their home addresses and a business table that lists their business addresses.

The problem is.... some of our contacts have their home addresses as preferred mailing addresses, others have their business addresses. I have a yes/no field in the table that says "MailingAddress?". When this checkbox is ticked i want a new record to be created in a table "tbl_MailingAddress"

Any ideas would be much appreciated, and please be gentle....it's been a while since i used Access and VBA.

Thanks
Bec :-)





why dont you use the add new method for the recordset object.
for example:

Expand|Select|Wrap|Line Numbers
  1. Dim myConnection As ADODB.Connection
  2. Dim tbl_MailingAddress_Table  As New ADODB.Recordset
  3.  
  4. Set myConnection = CurrentProject.Connection
  5. tbl_MailingAddress_Table.ActiveConnection = myConnection
  6.  
  7. tbl_MailingAddress_Table.CursorLocation = adUseClient
  8. tbl_MailingAddress_Table.CursorType = adOpenDynamic
  9. tbl_MailingAddress_Table.LockType = adLockOptimistic
  10. tbl_MailingAddress_Table.Open "tbl_MailingAddress", , , , adCmdTable
  11.  
  12. tbl_MailingAddress_Table.AddNew
  13. tbl_MailingAddress_Table.Fields(0) = value of field one
  14. tbl_MailingAddress_Table.Fields(1) = value of field two
  15. tbl_MailingAddress_Table.Fields(2) = value of field three
  16.  
  17. ...........and so on..............
  18. tbl_MailingAddress_Table.Update
  19.  
  20. tbl_MailingAddress_Table.close
  21. Set tbl_MailingAddress_Table = Nothing
  22. Set myConnection = Nothing

The code is general at the moment, make sure to study it and fix it to fit your needs,
with something like that code you can take anyvalue you want add it to the recordset (Table you want) and then its saved when the update method is used.
This is how i do it atleast :)


Hope this helps you,
Christina
Reply