AccessDiscussion 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
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.
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.
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 _
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
Set tdfNewDef = db.CreateTableDef(strTarget)
For i = 0 To rstSource.RecordCount
Set fldNewField = tdfNewDef.CreateField(CStr _
(i + 1), dbText)_
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
.Fields(0) = rstSource.Fields(i).Name
rstTarget.MoveFirst ' Fill each column of the
ânew table with a record from the original
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
.Fields(i) = rstSource.Fields(j)
Select Case Err
MsgBox "The table " & strTarget & " _
MsgBox "The table " & strSource &â _
MsgBox CStr(Err) & " " & _
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)
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.
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
Hope i've made myself clear.
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???