473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Insert Recordset Data

Hey there....

I am using a recordset to pull some data out of a table and in turn dump that data into a new table.

My code is as follows and works fine, but I am looking for assistance in dumping this into the new table.

Any help would be greatly appreciated.

--Art


Private Sub Form_Load()
Dim rs0 As Recordset
Dim ArraySplit() As String
Dim n As Integer
Set rs0 = CurrentDb.OpenRecordset("UserFile")

rs0.OpenRecordset

Do Until rs0.EOF
ArraySplit = Split(rs0![GroupList], "~")
For n = 0 To UBound(ArraySplit)
Debug.Print rs0![User] & ";" & rs0![Name] & ";" & _
rs0![Mgr] & ";" & ArraySplit(n)
Next n
rs0.MoveNext
Loop

rs0.Close

End Sub
Jul 19 '07 #1
10 3473
JKing
1,206 Expert 1GB
What will the table you're inserting into look like? In otherwords what fields are in the other table and what fields from the current recordset do you want to insert?
Jul 19 '07 #2
Thanks for the reply.

The only fields I need in the new table are the ones in the recordset above + a UID.

GroupList
User
Name
Mgr
Jul 19 '07 #3
JKing
1,206 Expert 1GB
Ok and what data types are all the fields? Are they text or numbers or dates.
Is the UID going to be an autonumber?
Jul 19 '07 #4
Sorry, I should've posted that 411.
The UID will be autonumber and the rest are plain old text.

Thanks again!
Jul 23 '07 #5
abolos
65
Hey there....

I am using a recordset to pull some data out of a table and in turn dump that data into a new table.

My code is as follows and works fine, but I am looking for assistance in dumping this into the new table.

Any help would be greatly appreciated.

--Art


Private Sub Form_Load()
Dim rs0 As Recordset
Dim ArraySplit() As String
Dim n As Integer
Set rs0 = CurrentDb.OpenRecordset("UserFile")

rs0.OpenRecordset

Do Until rs0.EOF
ArraySplit = Split(rs0![GroupList], "~")
For n = 0 To UBound(ArraySplit)
Debug.Print rs0![User] & ";" & rs0![Name] & ";" & _
rs0![Mgr] & ";" & ArraySplit(n)
Next n
rs0.MoveNext
Loop

rs0.Close

End Sub
The command you need is Insert:

form.recordset= insert into <table> [field1],[field2],... values val1,val2,...
Jul 23 '07 #6
The command you need is Insert:

form.recordset= insert into <table> [field1],[field2],... values val1,val2,...
Not really sure I follow how to add that line of code?
Jul 23 '07 #7
JKing
1,206 Expert 1GB
Hi, again. I think what you want to do is create a string for your sql and then execute it within the for loop.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim rs0 As Recordset
  3. Dim ArraySplit() As String
  4. Dim n As Integer
  5. Set rs0 = CurrentDb.OpenRecordset("UserFile")
  6.  
  7. rs0.OpenRecordset
  8.  
  9. Do Until rs0.EOF
  10. ArraySplit = Split(rs0![GroupList], "~")
  11. For n = 0 To UBound(ArraySplit)
  12. strSQL = "INSERT INTO yourTableName VALUES ('" & rs0![User] & "','" & rs0![Name] & "','" & _
  13. rs0![Mgr] & "','" & ArraySplit(n) & "')"
  14. Docmd.RunSQL(strSQL)
  15. Next n
  16. rs0.MoveNext
  17. Loop
  18.  
  19. rs0.Close
  20.  
  21. End Sub
  22.  
Notes:
yourTableName - replace this with actual name of the table you want to add this data to

The values you are inserting should be in the same order as they appear in the table you are adding them to. In this case we are inserting in the order of User, Name, MGR, GroupList. So the table we insert to should have columns in the order of UID, User, Name, MGR, GroupList.

Notice we did not include UID as part of the insert. This is because it is an autonumber and generates itself for each new record added.

Give that a try and let me know how you make out with it. If you have any further questions just ask.

JKing
Jul 23 '07 #8
Thanks so much!
This seems to work, but it is prompting me for the insert at each record.
Is there a way around that?
There are thousands of records.

Thanks!
--Art
Jul 23 '07 #9
JKing
1,206 Expert 1GB
Yes, there is a command for turning the warnings off though you must always be sure to turn them back on when your action is finished.

Expand|Select|Wrap|Line Numbers
  1. Docmd.SetWarnings False
  2.  
  3. 'Start of your insert code here
  4. 'more insert code here
  5. 'and some more here
  6. 'End of your insert code
  7.  
  8. Docmd.SetWarnings True 
  9.  
Jul 23 '07 #10
ADezii
8,834 Expert 8TB
Thanks so much!
This seems to work, but it is prompting me for the insert at each record.
Is there a way around that?
There are thousands of records.

Thanks!
--Art
This should work nicely for you with no Errors, just make a couple of personalized substitutions:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database, rs0 As DAO.Recordset
  2. Dim ArraySplit() As String, rstNew As DAO.Recordset
  3. Dim n As Integer
  4.  
  5. Set MyDB = CurrentDb()
  6. Set rs0 = MyDB.OpenRecordset("UserFile", dbOpenSnapshot)
  7. Set rstNew = MyDB.OpenRecordset("tblNewTable", dbOpenDynaset)
  8.  
  9. Do Until rs0.EOF
  10.   ArraySplit = Split(rs0![Grouplist], "~")
  11.   For n = 0 To UBound(ArraySplit)
  12.       With rstNew
  13.         .AddNew
  14.            ![Grouplist] = ArraySplit(n)
  15.            ![User] = rs0![User]
  16.            ![Name] = rs0![Name]
  17.            ![Mgr] = rs0![Mgr]
  18.         .Update
  19.       End With
  20.   Next n
  21.   rs0.MoveNext
  22. Loop
  23.  
  24. rs0.Close
  25. rstNew.Close
Jul 23 '07 #11

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

Similar topics

0
by: Weasel | last post by:
Does anyone know about a free API to insert textual data (like EXIF) into JPEG's and/or TIFF's? I've looked around but haven't found anything worth using. Most of the things I've found are,...
2
by: maltchev | last post by:
i need to insert data from an xml file into sql server table. the xml file contains only one record. how to insert the data? how to map the names of the fields in the xml file and the table?...
4
by: authorking | last post by:
I use the following code to insert a data record in to a datatable of an access database.But every time I execute the command, there will rise an exception and the insert operation can't be...
2
by: gaddampraneeth | last post by:
hi, I have two tables EmployeeMaster and EmployeeSkillsets common column in two tables in EmployeeID I am confused to write stored procedure to insert the data in two tables. As iam new to...
1
by: RYAN1214 | last post by:
I wanna make a form that can insert the data ,then write into database, what can i do in vb.net2005.I haven't many experience of vb.net,Plz HELP!
3
by: Prakashini | last post by:
Hi, I am new to html,asp and sql server. I want to insert the data into sql server using asp. I am getting the input from html screen. Can any one please help me. Many thanks in advance ...
1
by: anjanareddy | last post by:
Hai, i am unable to inserting duplicate data into UNIQUE index column, Is there any other process, to insert duplicate data into UNIQUE index column? plz let me know.. Thanks & Regards...
2
Inbaraj
by: Inbaraj | last post by:
HI.. I want to perform Bulk Insert of data using C# and oracle can any one help me how to perform this operation.... Plz help me with sample code..... with reg Inba
3
by: Kunal Desale | last post by:
Hi, How to insert/update data in foxpro table field having datatype MEMO using Linked Server? I have written sql insert queries in which i have used linked server to insert data into foxpro...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.