Fields Name into MsgBox

G

Guest

I wrote a function that displays query columns.
This function only displays the value of the Columns.
What do I need to do in order to display the Field Name as the first line?
Enclosed is the function:

Option Compare Database

Function GetQueryColumns(QueryName As String) As String
On Error GoTo Err_GetQueryColumns
Dim rs As ADODB.Recordset, cmd As ADODB.Command

Set cmd = New ADODB.Command

cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdStoredProc
cmd.CommandText = QueryName

Set rs = New ADODB.Recordset

rs.Open cmd, , adOpenStatic, adLockReadOnly
i = 1

While Not rs.EOF
stresult = stresult & "" & i & ". "
For J = 0 To rs.Fields.Count - 1
stresult = stresult & rs.Fields.Item(J) & " "
Next J
rs.MoveNext
i = i + 1
stresult = stresult & Chr(10)
Wend
GetQueryColumns = stresult

Exit_GetQueryColumns:
Exit Function

Err_GetQueryColumns:
GetQueryColumns = "Failed"
MsgBox Err.Number & " - " & Err.Description
GoTo Exit_GetQueryColumns

End Function



thanks,

tiyago
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top