Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Friday 22 April 2016

How to import excel data into a recordset in MSAcess

Firstly add Microsoft ActiveX Data Object 6.0 Library to your project
To add Microsoft ActiveX Data Object 6.0 Library go to tool click on References and then checked on Microsoft ActiveX Data Object 6.0 Library checkbox.


Dim rs As New ADODB.Recordset
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim strFile As String
Dim db As Database

strFile = Me.txtFilePath.Value
If strFile = "" Then Exit Sub

With con
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .ConnectionString = "Data Source='" & strFile & "'; " & "Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"
    .Open
End With

Set cmd.ActiveConnection = con
cmd.CommandType = adCmdText
cmd.CommandText = "SELECT distinct Business FROM [MAP$] "
rs.Open cmd


While Not rs.EOF
'Your code here
rs.MoveNext
Wend

No comments:

Post a Comment