alsoascientist
Registered User.
- Local time
- Today, 13:48
- Joined
- Mar 26, 2012
- Messages
- 39
Hi All,
I have some vba code that creates a temporary query and exports this to Excel. This issue that I now have is that there is now a requirement to make each of the field names / labels etc variable and listed in a master table (tblFieldNames). This is working fine for everything I'm doing apart from when I export the data this shows the StaticName (which is what each field is actually called) and I would like to show the FriendlyName which appears in each of the labels. tblFieldNames allows for a dlookup that I am using for everything else and I am hoping to either use the Caption property or Alilas for the field queries, though I have never used these before.
I have slipped a couple of lines into the code that I am using, however I don't seem to be able to get the right arguements to set the caption value. Has anyone got any experience of this that could see where I am going wrong?
I have this so far:
I have some vba code that creates a temporary query and exports this to Excel. This issue that I now have is that there is now a requirement to make each of the field names / labels etc variable and listed in a master table (tblFieldNames). This is working fine for everything I'm doing apart from when I export the data this shows the StaticName (which is what each field is actually called) and I would like to show the FriendlyName which appears in each of the labels. tblFieldNames allows for a dlookup that I am using for everything else and I am hoping to either use the Caption property or Alilas for the field queries, though I have never used these before.
I have slipped a couple of lines into the code that I am using, however I don't seem to be able to get the right arguements to set the caption value. Has anyone got any experience of this that could see where I am going wrong?
I have this so far:
Code:
Private Sub ExportBtn_Click()
On Error GoTo errHandler
'Takes the information to build the recordsource from the previous functions (bulit as SELECT / FROM / WHERE)
rept = BuildRept & " FROM " & "AllQuery" & BuildFilter
'Creates the query
DoCmd.DeleteObject acQuery, "qryTemp"
Set qdf = CurrentDb.CreateQueryDef("qryTemp", rept)
Dim fld As Field
'This is the part I hoped would change the names
For Each fld In qdf.Fields
fld.Caption = (DLookup("FriendlyName", "tblFieldNames", "SystemFieldName = '" & fld.Name & "'"))
Next
'Exports the query
DoCmd.OutputTo acOutputQuery, "qryTemp", acFormatXLS, , True
exitHandler:
Exit Sub
errHandler:
If Err.Number = 7874 Then
Resume Next
Else
MsgBox Err.Number & " - " & Err.Description
Resume exitHandler
End If
End Sub
Last edited: