Solved

Dynamically Set Query "Column Headings" Property

Posted on 2008-09-29
5
361 Views
Last Modified: 2012-06-27
I want to set a query's Column Headings property in VBA. Should be something like the below, just not sure of the syntax.
Any help is appreciated!
Thx,
MV
CurrentDb.QueryDefs (["qry_MYQUERY"].Properties.columnheadings = "A, B, C, D")
OR
Dim QDef As DAO.QueryDef
Set QDef = CurrentDb.QueryDefs("qry_MYQUERY")
QDef.Properties.columnheadings = "A, B, C, D")

Open in new window

0
Comment
Question by:Michael Vasilevsky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 85
ID: 22599842
There is no such property. The only way to do this is to alias your columns:

SELECT sCustFirstName AS [First Name], sCustLastName AS [Last Name] FROM tCustomers

this would show the query with "First Name" and "Last Name" columns.
0
 
LVL 10

Author Comment

by:Michael Vasilevsky
ID: 22600028
For a crosstab query there is. At least in design view. Is it not accessible through VBA? My problem is with a cross tab if there are no values in a crosstab column that column disappears and my formatting is messed up when I export to Excel...
0
 
LVL 10

Author Comment

by:Michael Vasilevsky
ID: 22600905
Ah figured it out. I need to use "PIVOT tbl_MyTable.MyField In ('" & "A" & "', '" & "B" & "', '" & "C" & "');

That forces three columns regardless of if A, B, or C don't have any data.
Thanks!

MV
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 22603523
Yes, it "aliases" query column names ... which is what I suggested you do. In other words, I provided you at least part of the answer.
0
 
LVL 10

Author Comment

by:Michael Vasilevsky
ID: 22613061
Ok the points are yours ;-)
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question