hi guys
im working on a project which i have almost compleated, which saves the data onto a text file (semi colon delimited ) however the second part requires me to import this file into access database by clicking a button on my projects gui, i already know how to do it the easy way open access import file but as i said it has to be done throught a one click process ,there are only 3 fileds required and the file cant be writted over only updated
if any one could guild me in the right direction i would be most greatful
thanks a bunch
stephen

Here's something to get started with

Dim ImportedFile As String
Dim ImportedLines() As String
Dim OneLine() As String
Dim strSQL As String
Dim i As Integer

If My.Computer.FileSystem.FileExists("C:\test.txt") Then
  ' Read the whole text file
  ImportedFile = My.Computer.FileSystem.ReadAllText("C:\test.txt")
  ' Separate lines
  ImportedLines = Strings.Split(ImportedFile, Environment.NewLine)
  For i = 0 To ImportedLines.GetUpperBound(0)
    ' Separate fields
    OneLine = Strings.Split(ImportedLines(i), ";")
    If OneLine.GetUpperBound(0) = 2 Then
      ' Build SQL insert statement
      strSQL = "INSERT INTO <tablename> VALUES ('" & OneLine(0) & "', '" & OneLine(1) & "', '" & OneLine(2) & "')"
      ' ExecuteNonQuery
    Else
      ' Error: Wrong number of fields
    End If
  Next i
Else
  ' Error: File not found
End If

Add all the needed connection etc. stuff. I assumed all the fields as textual, so do necessary casting (and error handling) and modify insert statement accordingly.

This article has been dead for over six months. Start a new discussion instead.