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
  #1 (permalink)  
Old January 31st, 2005, 06:41 AM
Friend of Wrox
 
Join Date: Aug 2004
Location: , , .
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default Running procedure - code window!

Hi to u all !
Would any one have time to teach me why when i've tried to run a
procedure on a code window i've a macro window openned with all
the names of procedures in the Db but the one i try to run?
Any help will be appreciated.
Regards Penta.

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

Have you declared your sub as Public??
Reply With Quote
  #3 (permalink)  
Old January 31st, 2005, 07:01 AM
Friend of Wrox
 
Join Date: Aug 2004
Location: , , .
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have declared it as Public and the result is the same.
I have lots of informations missing on the procedure because i have copied
it from Microsoft On-line help.Probably they suggest macros to have
the missing informations supplied.
Thanks JpJoe for ur attention.
P.

Reply With Quote
  #4 (permalink)  
Old January 31st, 2005, 07:08 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you supply the link you used?
Reply With Quote
  #5 (permalink)  
Old January 31st, 2005, 07:55 AM
Friend of Wrox
 
Join Date: Aug 2004
Location: , , .
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am sending u the code from the link:

Transpose table access 2002
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), dbText)_
  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

                              On-line help from Microsoft
            30/01/2005


Reply With Quote
  #6 (permalink)  
Old January 31st, 2005, 08:12 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I dont think you can call functions from the macro window. you can only call them from code or expressions. I might be wrong though.

What i would do is create a sub that calls the function -

Sub CallTransposerFunction() 'No arguments
    Dim strSrc As String
    Dim strTgt As String
    'Populate the variables required
    StrSrc = "Some String"
    strTgt = "Another String"
    'And call the function
    Call Transposer (strSrc, strTgt)
End Sub

Note - Dont use arguments in the sub or else it wont appear. you need to Populate the variables inside the sub and pass the lot to your function.

Hope this helps!!

Jp
Reply With Quote
  #7 (permalink)  
Old January 31st, 2005, 09:12 AM
Friend of Wrox
 
Join Date: Aug 2004
Location: , , .
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank u JpJoe !
I will give a try.
Regards P.

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

JpJoe !
Thanks again for ur help.
I have used ur procedure and it saved me from figuring out how to achieve
a higher step on the Transposing Task. But i'm still having two messages
when i run the function: 1) the field is not wide enough for ...; 2)no
current record ! About error message (1): the fields of the newtable are
wider than necessary; about error message (2): i have not a clue about it.
It showed up after i've cut the records of tb source to 1/3 of its past
total.
Hope i've made myself clear.
R.P.

Reply With Quote
  #9 (permalink)  
Old January 31st, 2005, 12:33 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Penta,

The Function you are running sets all the fields as text type at a length of 255 characters. Make sure that you are not trying to use this function with Memo datatypes. If so then you will need to add some code to the function to truncate and coerce the memotype to a texttype.

As for the No Current Record error, Is your source table Empty???

What is the structure of your source table?
Reply With Quote
  #10 (permalink)  
Old January 31st, 2005, 12:40 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: , , .
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm working on the Suppliers tb of the Northwind.mdb. And the source tb is not
empty for sure.
P.

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 01:14 PM.


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