borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (master, how can i disable my filter?)Next Topic (Redundant Data Verification!!! (Urgent)) New Topic New Poll Post Reply
AndreaVB Forum : Database : Import data from Excel to Access Database through VB Code Solved Topic
Poster Message
shanthi05msc
Level: Protégé

Registered: 25-09-2006
Posts: 4

icon Import data from Excel to Access Database through VB Code

I want to import data from Excel to Access Database through Vb Code.
For this I used the following code :

      CommonDialog1.InitDir = ""
      CommonDialog1.DialogTitle = "Select the Excel File to  import from"
      CommonDialog1.Filter = "Excel(*.xls)|*.xls"
      CommonDialog1.ShowOpen
  
        If CommonDialog1.FileName <> "" Then
            If FSO.FileExists(CommonDialog1.FileName) = True Then
               OpenTAConn 'This opens the database and objTAConn is the ADO recordset
               sqlString = "INSERT INTO test SELECT * from [Excel 8.0;DATABASE=" & CommonDialog1.FileName & ";HDR=YES;IMEX=1].[Sheet1$];"
            Else
               MsgBox "File not exists"
            Exit Sub
            End If
            CommonDialog1.FileName = ""
            objTAConn.Execute sqlString
            MsgBox "Successfully Imported"
            objTAConn.Close
            Set objTAConn = Nothing

This code is working fine but for each time When it is running, the data are inserted instead of appending.
The aim is no duplicate vaules should be entered.
Please help me to solve this problem.

25-09-2006 at 06:21 AM
View Profile Send Email to User Show All Posts | Quote Reply
shanthi05msc
Level: Protégé

Registered: 25-09-2006
Posts: 4
icon Import data from Excel to Access Database through VB Code

Is anbody there to answer my Question?

26-09-2006 at 04:26 AM
View Profile Send Email to User Show All Posts | Quote Reply
shanthi05msc
Level: Protégé

Registered: 25-09-2006
Posts: 4
icon Import data from Excel to Access Database through VB Code

Is anbody there to answer my Question?

26-09-2006 at 04:27 AM
View Profile Send Email to User Show All Posts | Quote Reply
shanthi05msc
Level: Protégé

Registered: 25-09-2006
Posts: 4
icon Re: Import data from Excel to Access Database through VB Code

I solved the above problem by using 'where' clause in the 'Insert' Statement. It is working fine now.

28-09-2006 at 04:24 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : Import data from Excel to Access Database through VB Code Solved Topic
Previous Topic (master, how can i disable my filter?)Next Topic (Redundant Data Verification!!! (Urgent)) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder