Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old January 31st, 2005, 12:49 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmmm. I have tried to run that function an it is fine!

Have you had to modify the function in any way??? If not paste the following duplicate into a new module and run the TransposeTable sub below.

'--------------------

Sub TransposeTable()
    Transposer "suppliers", "tbl_New_Suppliers"
End Sub


Function Transposer(strSource As String, strTarget As String)
 Dim db As DAO.Database
 Dim tdfNewDef As DAO.TableDef
 Dim fldNewField As DAO.Field
 Dim rstSource As DAO.Recordset, rstTarget As DAO.Recordset
 Dim i As Integer, j As Integer

 On Error GoTo Transposer_Err

 Set db = CurrentDb()
 Set rstSource = db.OpenRecordset(strSource)

 rstSource.MoveLast ' Create a new table to hold 'the transposed data.

 ' Create a field for each record in the original table.
 Set tdfNewDef = db.CreateTableDef(strTarget)
 For i = 0 To rstSource.RecordCount
    Set fldNewField = tdfNewDef.CreateField(CStr(i + 1), dbMemo)
     tdfNewDef.Fields.Append fldNewField
 Next i

 db.TableDefs.Append tdfNewDef ' Open the new 'table and fill the first field with field‘names from the original table.

 Set rstTarget = db.OpenRecordset(strTarget)
 For i = 0 To rstSource.Fields.Count - 1
       With rstTarget
        .AddNew
        .Fields(0) = rstSource.Fields(i).Name
        .Update
      End With
 Next i
 rstSource.MoveFirst
 rstTarget.MoveFirst ' Fill each column of the new table with a record from the original table.

 For j = 0 To rstSource.Fields.Count - 1

 'Begin with the second field, because the first field already contains the field names.
    For i = 1 To rstTarget.Fields.Count - 1
      With rstTarget
        .Edit
        .Fields(i) = rstSource.Fields(j)
         rstSource.MoveNext
        .Update
      End With
   Next i
     rstSource.MoveFirst
    rstTarget.MoveNext
 Next j
   db.Close
  Exit Function
Transposer_Err:
   Select Case Err
        Case 3010
           MsgBox "The table " & strTarget & " already exists."
        Case 3078
            MsgBox "The table " & strSource & " doesn 't exist."
         Case Else
             MsgBox CStr(Err) & " " & _
                   Err.Description
       End Select
     Exit Function
 End Function

'-----------------
Reply With Quote
  #12 (permalink)  
Old January 31st, 2005, 01:10 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: , , .
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry JpJoe !
I had worked the NewTb by myself and i've cut the code for CreateTable
because i didn't believe it would work. As they say in flying schools
the plane goes by itself, who puts it down is the pilot.
Thank u very much !
R.P.

Reply With Quote
  #13 (permalink)  
Old February 1st, 2005, 04:43 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No Problem,
Glad to be of help.;)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error When Running Stored Procedure Dwizz SQL Server 2000 4 May 15th, 2007 09:07 AM
Running oracle stored procedure from access Justine Access 9 December 21st, 2006 09:36 AM
Running stored procedure in Access VBA Bryon Burbage Access VBA 0 July 21st, 2006 09:14 AM
Check the strored procedure running in ASP code kapi.goel ASP.NET 1.0 and 1.1 Professional 0 May 17th, 2006 12:19 AM
ASP Code running Stored Procedure kapi.goel ASP.NET 1.0 and 1.1 Basics 0 May 17th, 2006 12:19 AM



All times are GMT -4. The time now is 08:05 AM.


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