Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

DAO excel import

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    DAO excel import

    Hello All,

    Looks like an EXCEL day on the board.

    I have a successful DAO EXCEL import operation.

    A customer used to send their EXCEL information in one large .XLS, now they send the information in 3-6 smaller .XLS files. I would like to just import each smaller XLS file. Trying to keep prep work down on the XLS files.

    After the first import with the DAO, it locks the import XLS file. I would like to use the same name for the 3-6 import files, so I can use the same import operation.

    How can I break the link to the EXCEL file with ALPHA still running? Right now I have to shut down ALPHA and then restart ALPHA. So that I can overwright the import XLS file with the same name(all 6 files need to be named the same).

    Am I looking at this wrong?

    Here is the import code:

    HTML Code:
    dim connectionString as c 
    connectionString = "{A5API='Excel',A5Syntax='Excel',FileName='C:\alphaimport\hsimport.xls'}" 
    delete options 
    dim options as p 
    options.ConsolidateArguments= .t.
    options.AddTablesToDatabase= .f.
    options.ShowProgress= .t.
    options.AllowCancel= .t.
     
    delete a_import
    dim a_import[0] as p 
     
    a_import[].ObjectName = "Sheet1$"
    a_import[..].SQLSelectStatement = "SELECT PCode, [Roll Number], BWt, Width, Diameter, [Gross Wt], CUSTOMER FROM [Sheet1$]"
    a_import[..].SQLType = "Portable"
    a_import[..].Arguments = ""
    a_import[..].ImportType = "Append to existing table"
    a_import[..].AppendOption = "Append all"
    a_import[..].AppendToTableName = a5.get_path() + chr(92) + "hs_xls_imp"+".dbf"
    a_import[..].AppendFieldMap = <<%txt%
    Customer|Customer
    Pcode|Pcode
    Roll_number|Roll_number
    Bwt|Bwt
    Width|Width
    Diameter|Diameter
    Gross_wt|Gross_wt
    %txt%
     
    dim flagSilent as l
    delete args 
    dim args as sql::arguments
    flagSilent = .f.
    delete p 
    dim p as p 
    p = a5_AlphaDAO_Import(connectionString,a_import,options,flagSilent,args)
    'p has an .hasError and .errorText property
    'a_import[] has the following properties for each item: .countRecordsImported, .hasError, .errorText, .userCancelled
    Thanks in advance

    Ed

    #2
    Re: DAO excel import

    Ed, I've never done anything quite like this but I did notice in the Help:

    It is very important that you close your connections at your end of your scripts, or else, if your script repeatedly opens connections, you will run out of resources. To close an open connection, you use the connection object's . Close() method.
    This was under the topic "Using AlphaDAO with XBasic".

    I don't see anywhere that you have "released" your .xls file from Alpha which is why it is locking it up. Closing the connection should free it up for manipulation.

    Comment


      #3
      Re: DAO excel import

      Hi Doug,

      I am on it right now. Thanks for the pointer.

      Ed

      Comment


        #4
        Re: DAO excel import

        Still no success.

        I have gone over "Creating an object" and SQL::Connection::Close(), and have tried various methods trying to turn the original operation made by the genie into a script.

        In the interactive window I have tired this from "Creating an Object" in the help file:

        HTML Code:
        dim conn as SQL::connection
        conn.open("{A5API=Excel,FileName='C:\alphaimport\hsimport.xls'}")
        conn.close()
        ERROR: Argument is incorrect data type
        The above tested fine, till the conn.close().......The example in the help file was actually opening up a Access data base, but the "Conn.open()" above went successful, even with testing the link to the EXCEL file.
        When I added the "conn.close() it threw up the ERROR message.

        When I tried to modify the code from the genie, I kept getting the same ERROR: as above.

        The below script imports fine, but when I try and delete the import EXCEL file, it is still locked.

        HTML Code:
        dim connectionString as c 
        c 
        delete options 
        dim options as p 
        options.C .f.
        options.ShowProgress= .t.
        options.AllowCancel= .t.
         
        delete a_import
        dim a_import[0] as p 
         
        a_import[].ObjectName = "Sheet1$"
        a_import[..].SQLSelectStatement = "SELECT PCode, [Roll Number], BWt, Width, Diameter, [Gross Wt], CUSTOMER FROM [Sheet1$]"
        a_import[..].SQLType = "Portable"
        a_import[..].Arguments = ""
        a_import[..].ImportType = "Append to existing table"
        a_import[..].AppendOption = "Append all"
        a_import[..].AppendToTableName = a5.get_path() + chr(92) + "hs_xls_imp"+".dbf"
        a_import[..].AppendFieldMap = <<%txt%
        Customer|Customer
        Pcode|Pcode
        Roll_number|Roll_number
        Bwt|Bwt
        Width|Width
        Diameter|Diameter
        Gross_wt|Gross_wt
        %txt%
         
        dim flagSilent as l
        delete args 
        dim args as sql::arguments
        flagSilent = .f.
        delete p 
        dim p as p 
        p = a5_AlphaDAO_Import(connectionString,a_import,options,flagSilent,args)
        'p has an .hasError and .errorText property
        'a_import[] has the following properties for each item: .countRecordsImported, .hasError, .errorText, .userCancelled
        end 
        connectionstring.close()
        Everything works great, except for freeing up the EXCEL file, to import the next one. Still have to close/open ALPHA to free the EXCEL file.

        Stumped

        Ed

        Comment


          #5
          Re: DAO excel import

          Ed,

          Did you ever get this working to release the file? I have seen that I will have that issue.

          But first, I can't get the xbasic generated by the genie to run. Get an error
          Code:
          variable "args" not found.
          My code is similar to yours
          Code:
          dim connectionString as c 
          connectionString = "{A5API='Excel',A5Syntax='Excel',FileName=" +quote(vFile) +"}" 
          
          delete options 
          dim options as p 
          options.ConsolidateArguments= .t.
          options.AddTablesToDatabase= .f.
          options.ShowProgress= .t.
          options.AllowCancel= .t.
          
          
          delete a_import
          dim a_import[0] as p 
          
          
          a_import[].ObjectName = "FinesCost$"
          'a_import[].ObjectName = "Sheet1$"
          a_import[..].SQLSelectStatement = "SELECT * from [FinesCost$]"
          'a_import[..].SQLSelectStatement = "SELECT * from [Sheet1$]"
          a_import[..].SQLType = "Portable"
          a_import[..].Arguments = ""
          a_import[..].ImportType = "Create table"
          a_import[..].LocalTableName = a5.get_path() + chr(92) + "import_temp"+".dbf"
          a_import[..].LocalTableFieldDef = <<%txt%
          <SizeToFit=.T.>
          <ConvertTimeToDate=.T.>
          <DefineFieldOverrides=.F.>
          <OverrideDefinitions="">
          %txt%
          a_import[..].OverwriteOption = "Overwrite without prompting"
          
          dim flagSilent as l
          flagSilent = .f.
          delete p 
          dim p as p 
          p = a5_AlphaDAO_Import(connectionString,a_import,options,flagSilent,args)
          Bill.

          Comment


            #6
            Re: DAO excel import

            Code:
            p = a5_AlphaDAO_Import(connectionString,a_import,options,flagSilent)
            Since you don't have arguments, ie args, take it off the last argument to the function.

            Did the genie gen that code or did you steal it and modify it???
            Al Buchholz
            Bookwood Systems, LTD
            Weekly QReportBuilder Webinars Thursday 1 pm CST

            Occam's Razor - KISS
            Normalize till it hurts - De-normalize till it works.
            Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
            When we triage a problem it is much easier to read sample systems than to read a mind.
            "Make it as simple as possible, but not simpler."
            Albert Einstein

            http://www.iadn.com/images/media/iadn_member.png

            Comment


              #7
              Re: DAO excel import

              Hey Bill & Al,

              No. I have not found a way to disconnect as of yet, without the restart.

              I will give Al's suggestion a shot with the last argument. It sure would be nice for it to just disconnect from the excel file after the import.

              The code I posted is from the DAO genie.


              Ed

              Comment


                #8
                Re: DAO excel import

                Thanks guys,

                I could not get back to post before Al did, but found that the xbasic from design mode in the import genie is correct. The xbasic obtained from the object on the control panel is missing these lines
                Code:
                delete args 
                dim args as sql::arguments
                adding those solves the problem. I'll report to Alpha.

                NOW my next issue has to do with Excel sheet names. My previous method of importing was with OLE to Excel - when Excel could save as DBF. If I did not know the sheet name I could always use a numeric sheet number to reference the sheet.

                With the ADO import, is there a way to reference a numeric sheet number, regardless of sheet name? FinesCost is sheet name, and imports correctly. I took a stab at Sheet1 (alpha, not numeric) which does not work.
                Code:
                a_import[].ObjectName = "FinesCost$"
                'a_import[].ObjectName = "Sheet1$"
                a_import[..].SQLSelectStatement = "SELECT * from [FinesCost$]"
                'a_import[..].SQLSelectStatement = "SELECT * from [Sheet1$]"
                Any thoughts on how to use a numeric sheet number? There is no autocomplete on "a_import[]." so difficult to guess.

                Bill.

                Comment


                  #9
                  Re: DAO excel import

                  One step further.

                  Code:
                  dim conn as SQL::Connection
                  ?conn.open("{A5API='Excel',A5Syntax='Excel',FileName='D:\Book1.xls'}" )
                  = .T.
                  ?conn.ListTables()
                  = abc$
                  def$
                  Sheet3$
                  So I can preprocess to get the sheet names. Problem is that they are not in numeric order. "def$" is the first sheet and "abc$" is the second sheet. So I still don't know how to get sheet 1.

                  Interestingly, ?conn does not show the ListTables() method, so there may be an obvious method that I am not seeing.

                  Bill.

                  Comment


                    #10
                    Re: DAO excel import

                    Hi Bill,
                    Interestingly, ?conn does not show the ListTables() method, so there may be an obvious method that I am not seeing.
                    If you would have placed a period after ?conn you would have seen all the possible functions associated with conn.....ListTables() is among them.

                    I could not find anything regarding sheet numbers--sorry. Maybe Stan Mathews has some insight and will respond as I know he works with Alpha/Excel more than most here.
                    Mike
                    __________________________________________
                    It is only when we forget all our learning that we begin to know.
                    It's not what you look at that matters, it's what you see.
                    Henry David Thoreau
                    __________________________________________



                    Comment


                      #11
                      Re: DAO excel import

                      I get
                      Code:
                      dim conn as sql::connection
                      ?conn.Open("{A5API='Excel',A5Syntax='Excel',FileName='D:\FinesCost012309.xls'}")
                      = .T.
                      
                      ?conn.
                      ERROR: Property not found
                      conn. subelement not found.
                      
                      ?conn
                      = V AddEventScript(ScriptSource as C [, Name as C])  'Add a connection event script with functions to handle one or more of the following events: 
                      
                          UpdateBegin(Connection as SQL::Connection, RowsExpected as N, BYREF ProgressInterval as N, Cancel BYREF as L)
                          UpdateProgress(Connection as SQL::Connection, RowsUpdated as N, RowsExpected as N, Cancel BYREF as L)
                          UpdateEnd(Connection as SQL::Connection, RowsUpdated as N)
                      L AddUser(UserName as C, Password as C)  'Create a new user in the currently connected database or server.
                      ...
                      Bill.

                      Comment


                        #12
                        Re: DAO excel import

                        Bill,

                        I simply used the interactive editor for convenience...the question mark makes no difference and I did NOT run ?conn.

                        Once the period is placed, Alpha gives you the function bubblehelp is all--that is what I was referring to. Take a look at the screenshot...


                        Mike
                        __________________________________________
                        It is only when we forget all our learning that we begin to know.
                        It's not what you look at that matters, it's what you see.
                        Henry David Thoreau
                        __________________________________________



                        Comment


                          #13
                          Re: DAO excel import

                          Yes Mike, I had later looked through the autocomplete list. It does show properties as well as methods. But did not see anything to help. Think I will add a "feature request".

                          Bill.

                          Comment

                          Working...
                          X