473,662 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I add leading zeros in an amount field and remove the decimal point?

62 New Member
I'm sure there's an obvious answer for this, but it's not coming to me. I have a make table query that figures a calculated amount for one column. I need to convert this table to a text file with no spaces or delimiters. The calculated field needs to be 8 characters with no dollar sign and no decimal point. How do I get the leading zeros in the file and the decimal point out?
Dec 15 '09 #1
5 3596
ADezii
8,834 Recognized Expert Expert
How about?
  1. Posting the Table Name
  2. Posting the Field Names and their Data Types
  3. Post some sample Data
  4. Example of how you would like the Exported Data to appear
Dec 15 '09 #2
stateemk
62 New Member
Currently there are three columns in this table. The first column is the EmpID which is a text field with 9 characters. The second column is SAM2down which is 10 characters. The third column is dedamt which is a calculated field. Its format is a number field with a double field size and Auto decimal places. Below is some sample data from the table.

EMP_ID SAM2down dedamt
999999999 MSECCMSECC 3
888888888 MSECCMSECC 5
777777777 MSECCMSECC 16
666666666 MSECCMSECC 40
555555555 MSECCMSECC 1
444444444 MSECCMSECC 7.5
333333333 MSECCMSECC 2

Here is what I would like it to look like in the text file.

999999999MSECCM SECC00000300
888888888 MSECCMSECC00000 500
777777777 MSECCMSECC00001 600
666666666 MSECCMSECC00004 000
555555555MSECCM SECC00000100
444444444MSECCM SECC00000750
333333333 MSECCMSECC00000 200
Dec 15 '09 #3
hjozinovic
167 New Member
stateemk,

I would first create such field in query and then take it out to a text file.
To create such field you can use expression in your query like this:
Expand|Select|Wrap|Line Numbers
  1. FinalString: [EMP_ID]&Format(Fix([dedamt]) & Right(Format([dedamt];"#,00");2);"00000000")
Please note here that i'm using symbols ; and , as it is adjusted to my local settings (Croatia)
You might need to replace some of those with your own smbols, but you should get the result.
regards,
h.
Dec 15 '09 #4
ADezii
8,834 Recognized Expert Expert
Assuming your Table Name is Table2, the following code will Export the contents of the 3 Fields in this Table to a Text File named Results.txt in the Root Directory of Drive C:, namely (C:\Results.txt ). You can change the Path of the Constant (conOUTPUT_FILE ) to any Folder/File name you like. There will be no Delimiters between the Fields, and no Decimal Points in the Calculated Field. The results of the Calculated Column will be as you requested. You can just as easily run this code against the Query itself and not Create the Table, if you so desire.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rst As DAO.Recordset
  3. Const conOUTPUT_FILE As String = "C:\Results.txt"
  4.  
  5. Set MyDB = CurrentDb
  6. Set rst = MyDB.OpenRecordset("Table2", dbOpenForwardOnly)
  7.  
  8. Open conOUTPUT_FILE For Output As #1
  9.  
  10. With rst
  11.   Do While Not .EOF
  12.     Print #1, ![EMP_ID] & ![SAM2down] & Format((100 * ![dedamt]), "00000000")
  13.       .MoveNext
  14.   Loop
  15. End With
  16.  
  17. rst.Close
  18. Set rst = Nothing
  19. Close #1
Dec 15 '09 #5
stateemk
62 New Member
Thanks for the suggestions. I will try tomorrow to see what happens and let you know.
Dec 15 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
13778
by: david | last post by:
Hi, I have an application as follows: MySQL database Back-Eend linked to MS Access Front-End and ASP Web Application. I require users to enter Serial Numbers such as: 0105123567 (10 digits), the first 4 being the month and year (mmyy)
5
11497
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in anticipation, Regards,
1
17338
by: Jean-michel | last post by:
I need to convert a decimal field to char() but also trim the leading zeroes. Any idea? I could not find any function to do that.
1
4547
by: mmmgood1 | last post by:
Help, I'm linking an excel spreadsheet in access and I have datafields with leading zeros (01021). When the file is linked in access, I get a #num in the field with the leading zeros. The zeros are needed. I've formated the field to be a text field, general number, and number and still I get the #num! error, or the leading zero is dropped. Can someone help before I pull more of my hair. Thanks a bunch.
6
5301
by: Clint Stowers | last post by:
Using A2k Exporting a query to a CSV file. The problem is any text fields (i.e. 000345) lose any leading zeros. Exporting to an excel file this problem does not exist. Tried to create a SpecificationName via the Export Wizard without success. Obviously doing something wrong.
5
20405
by: OneDay | last post by:
I've got a field that has some old data with text in it, but all forward data will be a 3 digit number. But many of the numbers are still only 2 digits. I would like to force the leading zero in the entry of the field. For example if the number 77 is entered into the field, 077 will display. How do I format to force the leading zero?
2
5661
by: chris | last post by:
Hi, I have a simple ms access application that allows you to scan barcodes in to a form which stores them in the database. The barcodes are 6 digits in length e.g. 555666 but my handheld scanner always adds a leading zero - e.g. 0555666. You can get round this problem by changing the database design for the field where this is stored from text to number format. However, when it comes to quickly doing a search for a code - CTRL + F
9
8650
by: Chester | last post by:
I'm working on an app that records data collected by service technicians (VB.Net front-end, SQL Server 2000 back end). The technicians need to record numbers with varying scale and precision. For example, they may record one reading as 63.45 and the next as 123.1 and a third as 1.32456. That's fine - those can be saved as floating point numbers (very little math is done with these numbers so I'm not too worried about strange floating...
0
4091
by: Monty | last post by:
Hi All, I am having a problem with leading zeros being stripped from fields in a CSV file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing a CSV file like so: sSQL = "SELECT * FROM " sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ Microsoft.VisualBasic.FileIO.FileSystem.GetParentPath(msFile) & _
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8344
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8546
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.