Trevor G
Well-known Member
- Joined
- Jul 17, 2008
- Messages
- 6,825
- Office Version
- 365
- Platform
- Windows
Hi I am using code to import a csv file but receive a message box stating this is a SYLK file, but cannot load it, either the file has errors (which it doesn't 4 rows with 4 columns all text entries) or it is not a SYLK file format.
Can anyone help get ride of this message box
My code is shown here
Option Compare Database<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
Option Explicit<o></o>
<o> </o>
Function import1()<o></o>
Dim ws As Excel.Application<o></o>
Dim cnn As ADODB.Connection<o></o>
Dim rst As ADODB.Recordset<o></o>
<o> </o>
Set cnn = CurrentProject.Connection<o></o>
Set rst = New ADODB.Recordset<o></o>
Set ws = CreateObject("Excel.Application")<o></o>
ws.Workbooks.Open "F:\Data\tblPeeps.csv"<o></o>
rst.Open "tblPeeps", cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect<o></o>
ws.Sheets("tblpeeps").Select<o></o>
ws.Range("A2").Select<o></o>
Do Until ws.ActiveCell.Value = ""<o></o>
With rst<o></o>
.AddNew<o></o>
.Fields("Title").Value = ws.ActiveCell.Offset(0, 1).Value<o></o>
.Fields("FirstName").Value = ws.ActiveCell.Offset(0, 2).Value<o></o>
.Fields("LastName").Value = ws.ActiveCell.Offset(0, 3).Value<o></o>
.Fields("JobTitle").Value = ws.ActiveCell.Offset(0, 4).Value<o></o>
.Fields("Company").Value = ws.ActiveCell.Offset(0, 5).Value<o></o>
.Update<o></o>
End With<o></o>
ws.ActiveCell.Offset(1, 0).Select<o></o>
Loop<o></o>
MsgBox "Records have been added"<o></o>
<o> </o>
End Function
Thank you
Can anyone help get ride of this message box
My code is shown here
Option Compare Database<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
Option Explicit<o></o>
<o> </o>
Function import1()<o></o>
Dim ws As Excel.Application<o></o>
Dim cnn As ADODB.Connection<o></o>
Dim rst As ADODB.Recordset<o></o>
<o> </o>
Set cnn = CurrentProject.Connection<o></o>
Set rst = New ADODB.Recordset<o></o>
Set ws = CreateObject("Excel.Application")<o></o>
ws.Workbooks.Open "F:\Data\tblPeeps.csv"<o></o>
rst.Open "tblPeeps", cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect<o></o>
ws.Sheets("tblpeeps").Select<o></o>
ws.Range("A2").Select<o></o>
Do Until ws.ActiveCell.Value = ""<o></o>
With rst<o></o>
.AddNew<o></o>
.Fields("Title").Value = ws.ActiveCell.Offset(0, 1).Value<o></o>
.Fields("FirstName").Value = ws.ActiveCell.Offset(0, 2).Value<o></o>
.Fields("LastName").Value = ws.ActiveCell.Offset(0, 3).Value<o></o>
.Fields("JobTitle").Value = ws.ActiveCell.Offset(0, 4).Value<o></o>
.Fields("Company").Value = ws.ActiveCell.Offset(0, 5).Value<o></o>
.Update<o></o>
End With<o></o>
ws.ActiveCell.Offset(1, 0).Select<o></o>
Loop<o></o>
MsgBox "Records have been added"<o></o>
<o> </o>
End Function
Thank you