Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics 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 May 15th, 2006, 12:31 AM
Authorized User
 
Join Date: Aug 2005
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO recordset to table

good morning everybody
...i've a ADO named "Distributor" with cmdText source ... the sql statement is "SELECT * FROM Distributors ORDER BY DistributorID;"

now i've placed button, whenever i press that button, all the records that are in the recordset of Distributor should be copied to a table that is named as "DistributorTwo", but before this, the table "DistributorTwo" should be emptied.

i m sorry my english is poor, but i hope u'll understand my problem.

w8ing 4 a good reply

 
Old May 15th, 2006, 03:11 AM
Authorized User
 
Join Date: Mar 2006
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Private Sub Command4_Click()
'you use ADO Connection object (named e.g. Conn)

  Conn.Execute "DELETE * FROM DistributorTwo"
  Conn.Execute "INSERT INTO DistributorTwo SELECT * FROM Distributors ORDER BY DistributorID"

End Sub

 
Old May 16th, 2006, 12:24 AM
Authorized User
 
Join Date: Aug 2005
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ooo no no no no

actually i dont want this... i want 2 copy the records from the recordset, not from the table ... coz ... the recordset is sometimge based on some criteria, there4 everytime the recordset is different, but the way u've told will copy all the records from one table 2 the other ... i want 2 copy the records from the recordset to a table

plz try 2 help me

 
Old May 16th, 2006, 02:59 AM
Authorized User
 
Join Date: Mar 2006
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok,
You may use some cycle e.g.:

Private Sub Command4_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim i As Long

  Set conn = 'set your connection

  conn.Execute "DELETE * FROM DistributorTwo"

  rs.CursorLocation = adUseClient
  rs.CursorType = adOpenStatic
  rs.LockType = adLockOptimistic
  rs.ActiveConnection = conn
  rs.Open 'set your SQL command to open

  rs2.CursorLocation = adUseClient
  rs2.CursorType = adOpenStatic
  rs2.LockType = adLockOptimistic
  rs2.ActiveConnection = conn
  rs2.Open "SELECT * FROM DistributorTwo"

  Do While rs.EOF = False
    rs2.AddNew
    For i = 0 To rs.Fields.Count - 1
      rs2.Fields(i).Value = rs.Fields(i).Value
    Next i
    rs2.Update
    rs.MoveNext
  Loop

  rs2.Close
  rs.Close
  conn.Close

  Set rs2 = Nothing
  Set rs = Nothing
  Set conn = Nothing

End Sub

Peko






Similar Threads
Thread Thread Starter Forum Replies Last Post
Clone DAO Recordset into ADO Recordset kamrans74 VB How-To 0 March 6th, 2007 11:57 AM
ADO Recordset Scootterp Access VBA 4 February 27th, 2006 06:44 PM
Convert ADO recordset to DAO recordset andrew_taft Access 1 May 5th, 2004 02:31 PM
Ado Recordset Filtering problem abumishal Access VBA 0 March 30th, 2004 01:11 PM
ADO Recordset and SQL Statements Dataman Access VBA 4 March 21st, 2004 06:19 PM





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