Question : MS Access Powerpoint VBA

Hi,
I need Experts help to modify the attached code.

I need to display the caption of the table fields in the spreadsheet not the Field name.
How do I change this ?
 rng.Offset(0, i).Value = rs.Fields(i).Name
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
Public Sub RefreshExcelObject(Optional str As String)
    Dim db              As DAO.database
    Dim rs              As DAO.Recordset
    Dim sh              As OWC11.Worksheet
    Dim rng             As OWC11.Range
    Dim strTable        As String
    Dim i               As Long
    Dim j               As Long
    Dim k               As Long
    
    Call Assign_Slide2
    Set db = OpenDatabase(Slide2.Tags("DBPath"))
    strTable = Slide2.Tags("Table")
    Set rs = db.OpenRecordset("Select * from " & strTable)
    Set sh = Slide2.Spreadsheet1.Sheets(1)
    sh.UsedRange.ClearContents
    With sh
        Set rng = .Cells(1, 1)
        For i = 0 To rs.Fields.Count - 1
            rng.Offset(0, i).Value = rs.Fields(i).Name
        Next i
        i = 1
        Do While Not rs.EOF
            j = 0
            For k = 0 To rs.Fields.Count - 1
                rng.Offset(i, j).Value = rs.Fields(k).Value
                j = j + 1
            Next k
            i = i + 1
            rs.MoveNext
        Loop
        
        rs.Close
        Set rs = Nothing
    End With
    db.Close
    Set db = Nothing
End Sub

Answer : MS Access Powerpoint VBA

use currentdb.TableDefs("tblName").Fields("fldName").Properties("Caption").value

replacing tblName and fldName with your actual names.
Random Solutions  
 
programming4us programming4us