Solved

Excel output from Access VBA

Posted on 2014-12-19
9
196 Views
Last Modified: 2014-12-22
I am creating a spread sheet from Access using VBA.  I have a serial field that should be displayed as text all the time but am having a problem with it. The serial number field contains alpha and numeric data.  When the serial number happens to be a large number (eg: 5305588100043) it displays on the spreadsheet as 5.30559E+12.  Within the VBA code to create the spreadsheet, I have the serial number cell set to objXLS.Cells(1, 8).NumberFormat = "@".  
Is there any other way to force this cell to always display full text regardless of what data is in that field?
Thanks for your help
Art.
0
Comment
Question by:ajwellman
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40509325
try forcing the serial number field to be text, in a query

select cstr([SerialNumber]), f1,f2
from tablex

then export the query

or explicitly fill the cell with
objXLS.Cells(1, 8).value=cstr(rs!serialNumber)
0
 

Author Comment

by:ajwellman
ID: 40509371
Thanks for the quick response.

I just tried both of these and it is still showing up as 5.30559E+12 when I open the spreadsheet.
I'm sure it must be something that I am doing, but I sure don't see it.

Art
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40509381
how are you passing the info to Excel?  post your codes
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40509400
or try
objXLS.Cells(1, 8).NumberFormat = "0"
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40510651
You can use the very oldest method to force a string in a spreadsheet:

Select
    Chr(39) & CStr([SerialNumber]) As SNo,
    <other fields>
From
    tblYourTable

and export this query or use:

    objXLS.Cells(1, 8).Value=Chr(39) & CStr(rst![SerialNumber].Value)

/gustav
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40511862
Also, make sure the column is wide enough to display the number (whether it is an actual number or text)
0
 

Author Comment

by:ajwellman
ID: 40512952
Thanks Gustav,
The oldest method worked great.  
Thanks again for your quick response.
Art.
0
 

Author Closing Comment

by:ajwellman
ID: 40512957
Great help.  Thanks
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40512971
You are welcome!

/gustav
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Use a Combo-Box to do a Search 26 25
Add records to a form to a table 11 37
Access 2016 - query 23 59
Cascading Combo boxes between 2 sub navigation forms 1 12
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

785 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