Results 1 to 13 of 13
  1. #1
    GMadd is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Dec 2020
    Posts
    5

    Remove leading Zeros in table from Excel

    I want to start off by saying I am new to using access. At my job I inherited an access database to manage and the funny thing is I know very little about how it works and I am slowly learning. The data base uses several reports for our SAP system that are downloaded into an excel file that are linked to the access database. Due to a recent upgrade with our SAP I can only get my reports in a xlsx format (before they were txt files); I was able to figure out how to update the linked files but I have an issue with just one of the four reports coming from SAP. The report has a column in it that is our sales order number but for some reason when I download the report from SAP it stores the sales order number as general format so it does not drop the leading zeros but the other three reports drop the leading zeros. Now my problem is this report that has the leading zeros is not being used because the other reports do not have the leading zeros so access does not know how add the data to the master report I am getting from access. I need to know how to tell access to drop the leading zeros when it completes the query or somehow set the table in access to drop the leading zeros (without creating a VBA). Currently I am changing the format in excel file so it comes over as a number but do not want to continue to do that.

    Thanks in-advance for the help

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    if you import the xl data into an intermediate (or final) table, where the field is set to a number, the leading zeros will vanish.

    Save new excel file the same file everytime. (make a macro to do it) like c:\temp\File2Import.xls


    LINK this file as an attached linked table in access.

    build your append query(ies) to import the data to the various tables


    put all this in a macro: mImportXLfiles


    now the import process is just 2 steps:
    1. Get a new excel file, save it to the c:\temp\File2Import.xls
    2. run the import macro.
    done

  3. #3
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Welcome to the forum..

    My first thought is to request the "High Priests of SAP" to modify the report to have the sales order number column exported in a number format. They, (the High Priests), are just using some dialect of SQL to create the report, so it should be an easy fix.... at least it was in my experience. (I am surprised that the reports output was changed from TXT to XLSX.)


    Your first post has me confused, so I've got questions:
    Quote Originally Posted by GMadd View Post
    ....The data base uses several reports for our SAP system that are downloaded into an excel file that are linked to the access database....
    The four reports are in one XLSX workbook?
    One workbook or four, they are linked to Access?



    Quote Originally Posted by GMadd View Post
    ...Due to a recent upgrade with our SAP I can only get my reports in a xlsx format (before they were txt files);
    The extension of the download(s) is/are .XLSX?
    Again, I am surprised that the download format was changed.



    Quote Originally Posted by GMadd View Post
    ..I was able to figure out how to update the linked files
    How/why are you updating the linked files???



    Quote Originally Posted by GMadd View Post
    Now my problem is this report that has the leading zeros is not being used because the other reports do not have the leading zeros so access does not know how add the data to the master report I am getting from access.
    What is the report record source?



    Quote Originally Posted by GMadd View Post
    I need to know how to tell access to drop the leading zeros when it completes the query or somehow set the table in access to drop the leading zeros
    What is the query? Maybe you could use the Val() function to convert the sales order number column from text to a number for the problem report.
    Where does the "table" come into play?


    What are the chances you would post the Access dB and the SAP reports?

  4. #4
    GMadd is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Dec 2020
    Posts
    5
    Yes I tried to get them to change the format but the stated they could not or would not. This report I have the problem with comes straight from a table in SAP so I don't think they could change the format. My problem child is the credit hold report I get from the CDHDR table out of SAP. The report grabs change doc object VERKBELEG in conjunction with VKM transactions. I pull the sales order number, time released and the date released from the report.

    Your first question
    I meant to write FROM SAP and not for SAP. The reports are all in different XLSX files that come from SAP. Each report is saved as an XLSX file on my computer and I have those files linked to this monster access database that tracks about 15 different things that has to do with on-time delivery performance and fill rates for our deliveries going to customers.

    Your second question
    the extension for the files is XLSX I do have the option to download text with tabs but SAP puts it in a bad format that I cannot work with

    Third question
    How/why are you updating the linked files???
    Every time I run the reports in SAP I save them as the same XLSX file names then open up my access database and run the queries. This is a daily report so the data changes. I am building a report that allows me to better figure out why a delivery was shipped late. If the order was on credit hold the late event does not get charged against the shipping DC or customer service (it's basically considered shipped on time).

    Forth question
    What is Report Record source? Not sure I understand that question... I have a query that pulls from the linked file (CDHDR.XLXS file) every time I run the master query. The master query runs 16 queries so I can get my final report.

    Fifth question
    What is the query? Maybe you could use the Val() function to convert the sales order number column from text to a number for the problem report.
    Where does the "table" come into play?
    There are two queries the first one the first deletes previous data and the second appends new data from the linked CDHDR.XLXS file. I think there is some way to tell the append query to use the Val() function to convert to a number but I have no idea how to do that. Below is a screen shot of the query that appends the new data. Object Value is the sales order number.
    Click image for larger version. 

Name:	2020-12-01_19-05-42.gif 
Views:	23 
Size:	29.1 KB 
ID:	43519

    Thanks again for your help.
    Last edited by GMadd; 12-01-2020 at 07:16 PM. Reason: Delete link, wasn't working anyway

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Post 4 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    OK, thanks. I think I understand a little better..

    So maybe you are not " updating the linked files", you are "importing the linked files" ?


    "The master query runs 16 queries".. Whew! I would like to see that query!


    I created an XLSX sheet with the first column "SalesOrder" as Text and a 2nd column "Description" also as text.
    I created a table in Access "TestTable" with 3 fields: ID - Autonumber, SalesOrder- Number-Integer and Description - Text.

    I linked the XLSX workbook (Book1.xlsx) to Access. The link name in Access is "Sheet1"
    I created a query (qryWithVal) to import the data from "Sheet1" (linked workbook) into "TestTable" (Access table).

    The SQL of qryWithVal is
    Code:
    INSERT INTO Testtable ( SalesOrder, Description )
    SELECT Val([SalesOrder]) AS SalesOrderNum, Sheet1.Description
    FROM Sheet1;
    The SalesOrder data was inserted into the TestTable as numbers.


    I also created a query to import just the two columns "SalesOrder" and "Description".
    This time the SalesOrder data was also inserted into the TestTable as numbers.
    Don't know why the import is not working correctly for you.

    I must have done something different than you.



    Maybe you will post the dB and the problem Excel workbook?

    Make a copy of the dB and delete all data.
    Make a copy of the Excel workbook and delete any sensitive data.



  7. #7
    GMadd is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Dec 2020
    Posts
    5
    Thanks for trying to help and I want to apologize because I know I have not been doing a good job of describing my issue. Also I want to remind you that I have zero training on how to setup an access database. I was given instructions on how to run this database to generate my reports and the rest I am figuring out on my own. I would love to take a class if you can suggest one.

    For the reports from SAP that are saved as XLSX files they are linked to my access database and every time I run the reports from SAP and save them as excel files the old data is overwritten in the XLSX file. I am not sure how the database grabs the data from the linked file called CDHDR other than the two queries (if that is what they really are) called Update - 010 - Credit hold table - delete previous data and Update - 020 - Credit hold table - append new data do something. Let me try to outline what I am doing on a daily basis with this database.



    1. Run my reports in SAP
    2. Open up this data base (attached) and go all the way down to the bottom and run the Macro called Update database
    3. When database is complete I run the query called Fill rate - 150 - weekly reason code query EXPORT
    4. Export weekly reason code query to a excel file called Fill rate - 150 - weekly reason code
    5. Open Fill rate - 150 - weekly reason code excel file and copy and paste data to a massive excel file called Reason Code Analysis that looks at the data I pasted and uses formulas and lookups to help me assign reason codes to the late deliveries
    6. After all reason codes are entered in the Reason Code Analysis excel file I copy data that is on one of the many tabs and paste it into the table on the access database called Invoice Details.
    7. The next day I start over with step 1.


    In the database I attached the linked excel file called CDHDR is where the Credit Hold data is located that comes from my SAP report. I run the CDHDR report in SAP and save it to the file called CDHDR.XLXS and never open it up in excel or even look at it. As stated before I have an issue because the sales order number is not saved as a number so it contains leading zeros causing a problem. I need to somehow have the database convert the sales order numbers to an actual number or just drop the leading zeros so the credit hold data is pulled into my Fill rate - 150 - weekly reason code query. I have no idea where the leading zeros need to be addressed.
    Thanks for trying to help and I want to apologize because I know I have not been doing a good job of describing my issue. Also I want to remind you that I have zero training on how to setup an access database. I was given instructions on how to run this database to generate my reports and the rest I am figuring out on my own. I would love to take a class if you can suggest one.

    For the reports from SAP that are saved as XLSX files they are linked to my access database and every time I run the reports from SAP and save them as excel files the old data is overwritten in the XLSX file. I am not sure how the database grabs the data from the linked file called CDHDR other than the two queries (if that is what they really are) called Update - 010 - Credit hold table - delete previous data and Update - 020 - Credit hold table - append new data do something. Let me try to outline what I am doing on a daily basis with this database.



    1. Run my reports in SAP
    2. Open up this data base (attached) and go all the way down to the bottom and run the Macro called Update database
    3. When database is complete I run the query called Fill rate - 150 - weekly reason code query EXPORT
    4. Export weekly reason code query to a excel file called Fill rate - 150 - weekly reason code
    5. Open Fill rate - 150 - weekly reason code excel file and copy and paste data to a massive excel file called Reason Code Analysis that looks at the data I pasted and uses formulas and lookups to help me assign reason codes to the late deliveries
    6. After all reason codes are entered in the Reason Code Analysis excel file I copy data that is on one of the many tabs and paste it into the table on the access database called Invoice Details.
    7. The next day I start over with step 1.


    In the database I attached the linked excel file called CDHDR is where the Credit Hold data is located that comes from my SAP report. I run the CDHDR report in SAP and save it to the file called CDHDR.XLXS and never open it up in excel or even look at it. As stated before I have an issue because the sales order number is not saved as a number so it contains leading zeros causing a problem. I need to somehow have the database convert the sales order numbers to an actual number or just drop the leading zeros so the credit hold data is pulled into my Fill rate - 150 - weekly reason code query. I have no idea where the leading zeros need to be addressed.

    I have added the database and the excel file
    Attached Files Attached Files

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    modify your queries to use the val function. There are a lot there, you'll know which ones.

    There is another way that might work for you. Instead of a linked table just use sql - something like this

    Code:
    SELECT Val([Object Value]) AS ObjectValue, XL.Date AS ODate, XL.Time AS OTime
    FROM (SELECT * FROM [sheet1$] AS xlData IN 'C:\Users\GMadden\Documents\CDHDR.XLSX'[Excel 12.0;HDR=yes;IMEX=0;ACCDB=Yes])  AS XL;
    Note that date and time are reserved words - can't get away with it from SAP, but change as soon as you can as above

  9. #9
    GMadd is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Dec 2020
    Posts
    5
    Quote Originally Posted by Ajax View Post
    modify your queries to use the val function. There are a lot there, you'll know which ones.

    I have no idea on how to do that. As stated before I am less than a novice access user.

    There is another way that might work for you. Instead of a linked table just use sql - something like this

    Code:
    SELECT Val([Object Value]) AS ObjectValue, XL.Date AS ODate, XL.Time AS OTime
    FROM (SELECT * FROM [sheet1$] AS xlData IN 'C:\Users\GMadden\Documents\CDHDR.XLSX'[Excel 12.0;HDR=yes;IMEX=0;ACCDB=Yes])  AS XL;
    Note that date and time are reserved words - can't get away with it from SAP, but change as soon as you can as above
    I have no idea on how to do that. As stated before I am less than a novice access user.

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    open a new query, go to the sql window (dropdown on the left of the ribbon or see SQL option bottom right of the window). Copy the code I provided and paste into the sql window - then run it.

    I have already adjusted it for the path to your file location per your linked table.

    Tip for the future, don't use macro's learn how to use vba.

    macro's have limited functionality, are difficult to debug and impossible to document. You'll also find it difficult to get help since 99%, (if not all) of responders use vba and at best have limited knowledge of macros

  11. #11
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I spent some time going through your dB and, IMHO, there are design issues that should be addressed. But since it seems to be working for you, I'll focus on the problem at hand.


    So in the Excel file CDHDR.XLSX, the first column is named "Object Value" (data type is TEXT). The data seems to be 10 characters - in this case they are numeric - and are left padded with zeros.
    In the Access table "Credit hold table", the corresponding field is named "Order number" (data type Short Text) - but not left padded.

    -----
    Warning: you should test this on a COPY of your dB or make a copy of the query and make the changes in the query copy.
    ----

    If you go the route of copying the query, you will rename the original: I added a suffix of "_Old".
    Then query copy name MUST be "Update - 020 - Credit hold table - append new data".
    Now you will have
    "Update - 020 - Credit hold table - append new data"
    "Update - 020 - Credit hold table - append new data_OLD".

    Edit the SQL of the query "Update - 020 - Credit hold table - append new data". Change the SQL to
    Code:
    INSERT INTO [Credit hold table] ( [Order number], [Date released], [Time released] )
    SELECT VAL(CDHDR.[Object Value]), CDHDR.Date, CDHDR.Time
    FROM CDHDR;
    The VAL() function will convert the text to a number (which removes the leading zeros), Access will automatically convert the number to text and append it to the [Order number] field in "Credit hold table".

    ---

    In my testing of the file you posted, there are 2387 rows in the spreadsheet, but only 2243 rows are appended.
    An error dialog box says 144 records not appended due to Key violations. (something like that). Because the field "Object Value" is set as the PK field, duplicate values are not allowed in that field.
    The Excel spreadsheet has duplicate values in the "Object Value" column, but with different Dates/Times. In the attached file, I highlighted the duplicates using yellow/gray and orange/blue.
    There are 1 duplicate for value "0006551806" (2 total), but there are a few "Object Value" with up to 3 duplicates (4 total). Could this affect your report?
    Attached Files Attached Files

  12. #12
    GMadd is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Dec 2020
    Posts
    5
    I did what you suggested and everything worked as you said it would. Thanks a lot for helping me out!!!
    I was aware of the duplicate values for the Object Value and it does not matter as long as one of the values gets recorded? If I have 3 duplicates does the database grab one of them or does it skip all of them because they are duplicates?



    Quote Originally Posted by ssanfu View Post
    I spent some time going through your dB and, IMHO, there are design issues that should be addressed. But since it seems to be working for you, I'll focus on the problem at hand.

    I am not surprised that there are design issues and if you want to help me out I am not going to stop you. Honestly I am scared almost everyday when I run this database since I know close to nothing about how to create a database like this. If this thing ever crashes completely I am not sure I'll do. Can you recommend some online Access classes that I can take to help me learn more about managing, understands and creating a database like this?

    So in the Excel file CDHDR.XLSX, the first column is named "Object Value" (data type is TEXT). The data seems to be 10 characters - in this case they are numeric - and are left padded with zeros.
    In the Access table "Credit hold table", the corresponding field is named "Order number" (data type Short Text) - but not left padded.

    -----
    Warning: you should test this on a COPY of your dB or make a copy of the query and make the changes in the query copy.
    ----

    If you go the route of copying the query, you will rename the original: I added a suffix of "_Old".
    Then query copy name MUST be "Update - 020 - Credit hold table - append new data".
    Now you will have
    "Update - 020 - Credit hold table - append new data"
    "Update - 020 - Credit hold table - append new data_OLD".

    Edit the SQL of the query "Update - 020 - Credit hold table - append new data". Change the SQL to
    Code:
    INSERT INTO [Credit hold table] ( [Order number], [Date released], [Time released] )
    SELECT VAL(CDHDR.[Object Value]), CDHDR.Date, CDHDR.Time
    FROM CDHDR;
    The VAL() function will convert the text to a number (which removes the leading zeros), Access will automatically convert the number to text and append it to the [Order number] field in "Credit hold table".

    ---

    In my testing of the file you posted, there are 2387 rows in the spreadsheet, but only 2243 rows are appended.
    An error dialog box says 144 records not appended due to Key violations. (something like that). Because the field "Object Value" is set as the PK field, duplicate values are not allowed in that field.
    The Excel spreadsheet has duplicate values in the "Object Value" column, but with different Dates/Times. In the attached file, I highlighted the duplicates using yellow/gray and orange/blue.
    There are 1 duplicate for value "0006551806" (2 total), but there are a few "Object Value" with up to 3 duplicates (4 total). Could this affect your report?

  13. #13
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by GMadd View Post
    I did what you suggested and everything worked as you said it would. Thanks a lot for helping me out!!!
    Excellent!
    Whew.... I'm glad I was able to explain it clearly enough.

    Quote Originally Posted by GMadd View Post
    I was aware of the duplicate values for the Object Value and it does not matter as long as one of the values gets recorded? If I have 3 duplicates does the database grab one of them or does it skip all of them because they are duplicates?
    If you have 3 duplicates, the first one gets appended and the other 2 are not added because there would be PK duplicates. PK values MUST be unique.



    Are you the only one that uses the dB?
    Until you learn more about Access, you should know the 3 rules of Computing.

    First: BACK UP.
    Second: BACK UP.
    And Third:
    V
    V
    V
    V
    V
    V
    V
    V
    V
    V
    BACK UP!!



    Seriously, I would suggest you make a back up at least daily. (Ched left the company?)

    I will look at the dB again when I get some time. But I don't know your business and don't know the work flow or requirements, so........



    Good luck with your project...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Delete Leading Zeros
    By KathyCo in forum Queries
    Replies: 4
    Last Post: 11-01-2016, 11:59 AM
  2. Do not add leading zeros
    By phifer2088 in forum Access
    Replies: 5
    Last Post: 03-02-2015, 10:05 AM
  3. Replies: 7
    Last Post: 09-20-2014, 06:48 PM
  4. Leading Zeros
    By dirtbiker1824 in forum Access
    Replies: 1
    Last Post: 03-14-2011, 02:16 PM
  5. Adding Leading Zeros
    By jo15765 in forum Access
    Replies: 13
    Last Post: 11-20-2010, 11:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums