Docmd.Transferspreadsheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • usha2
    New Member
    • Mar 2012
    • 23

    Docmd.Transferspreadsheet

    I am trying to impot a excel file and replace with existing table in database.
    Every time it import a extra automated field(F1),so it gives the error message:
    "Field'F1' doesnot exost in destination table'table name'"
    How can i impot my excel file into existing table,whose field names are same?And without autonum field?
    The code i craft is:
    Code:
    Private Sub cmdImport_click()
    Dim msg As String
    Dim button As Variant
    Dim title As String
    Dim response As Variant
    
    msg = "Is the updated file Task Import placed in File path with 'file name.xls'?"
    button = vbYesNo + vbDefaultButton2
    title = "File Location Checkpoint"
    
    response = MsgBox(msg, button, title)
    If response = vbYes Then
    'Delete old records from tbltask
       DoCmd.SetWarnings False
       DoCmd.RunSQL "Delete [dbaseTable name].* from [dbaseTable name]"
       DoCmd.SetWarnings True
    'Import new records from Excel file into tblTask
       DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "dbaseTable name", "File path with 'file name.xls'"
       DoCmd.OpenForm "Form1"
    End If
    End sub
    Thankful for helping always!
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    If the data in the spreadsheet doesn't match the layout of the table, then it's not going to work. Probably obvious, but you seemm to need to be told that so I have done so.

    Either make sure the data layout is the same, or else import the data into a separate table (that does match the data obviously) and follow that with an Append query to move the matching part of the data across to your originally-intended table.

    Comment

    • usha2
      New Member
      • Mar 2012
      • 23

      #3
      yes the layout of both excel file and access table are same.
      But when it impoting ,it automatically create a autonumber field,which is not matched.
      So should i create a table in database with F1 field?
      It again shows the error msg" F2...in destinationn table"
      or any way is there to replace a existing file with imported file.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        You say they're the same, yet Access says they're different. Whom do I believe?

        Why not explain the exact layout for each and we'll see which of you is correct, and how to move on from there.

        Comment

        • usha2
          New Member
          • Mar 2012
          • 23

          #5
          The existing table in data base has 4 field:
          1A
          2B
          3C
          4D
          (This is the impoted excel file by using File->Import)
          In this file i want to replace all my imported data of new excel file.
          The new excel file has also same field name,same sequence,same data type.
          only the thing is that,while it importing the new excel file,it join a autonumber field,with default naming"F1".
          Which means now the layout of new excel file is different.
          how can i got the solution of this autonumber field?

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            That doesn't make sense. How can there be a new field in those circumstances? This is still a contradiction. Please explain the situation clearly and illustrate the data (as your explanation is so unreliable I need something to give me a clue as to what you really mean). I can't help with this as it stands.

            Comment

            • usha2
              New Member
              • Mar 2012
              • 23

              #7
              The existed table has 4 fiels:
              Name(text)'Two space before this string.
              Fname(text)
              Lname(text)
              Email(text)
              Excel file try to import has 4 column;(All in Sheet1)
              Name(text)'In A1 ,Two space before this string.
              Fname(text)'In B1
              Lname(text)'In C1
              Email(text)'In D1
              executing my 1st posted code,the error msg comes"F1.."
              Next i tried by changing in my code:
              Code:
              DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8 "dbaseTable name", "File path with 'file name.xls',"A1:D1000""
              now error msg is:
              "Field' Name' doesnot exist..."
              Last edited by usha2; Mar 29 '12, 06:09 PM. Reason: add code

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32633

                #8
                Still no example data, and I have no idea what you mean when you say :
                "Name(text)'Two space before this string."

                The explanation is more detailed certainly, but I see nothing here to explain why that behaviour might occur. ... which leads us neatly back to the missing example data which was requested, but still not included in your post.

                Comment

                Working...