Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
| 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 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
  #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.

  #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??
  #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.

  #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?
  #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


  #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
  #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.

  #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.

  #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?
  #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.





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





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