[AccessD] still struggling with inserting to access table

Oleg_123 at xuppa.com Oleg_123 at xuppa.com
Tue Oct 21 08:44:31 CDT 2003


>>problems for last Names thats have apostrophe

>
> You need double singles for these names (or any value in a sql string
> with an apostrophe in it).  Surround the value with a Replace ...
>
> Replace(arecord(0), "'","''")
>

got the replace function, got the split function;
but when i try to implement replace function at that part of the code it
gives "by Ref  mistake" (in diff part of the same code it work fine)


--------

Private Sub Command14_Click()

 MsgBox ("hey")
 Dim fs As New Scripting.FileSystemObject
Dim ts As Scripting.TextStream
Dim strLine As String
Dim aRecord
Dim strSQL As String
Dim db As DAO.Database
Dim i As Integer

Set db = CurrentDb


If fs.FileExists("U:\Users\HRIS\oleg\cars testing\trainFROM.csv") Then
    Set ts = fs.OpenTextFile("U:\Users\HRIS\oleg\cars
testing\trainFROM.csv", ForReading)

    Do Until ts.AtEndOfStream

        strLine = ts.ReadLine
       'strLine = Replace(strLine, """, " ") 'need to replace " with space
       strLine = Replace(strLine, ",", vbTab)

        aRecord = Split(strLine, vbTab)
        aRecord(8) = Mid(aRecord(8), 5) & Left(aRecord(8), 4)


        strSQL = "INSERT into Table1Testing(a, b, c,d,e) Values(" & "'" &
aRecord(0) & "','" & aRecord(1) & "','" & Replace(aRecord(2), "'",
"''") & "','" & Replace(aRecord(3), "'", "''") & "','" &
Replace(aRecord(4), "'", "''") & "')"


        Debug.Print strSQL
        CurrentDb.Execute (strSQL)

    Loop
Else
     MsgBox ("file doesn't exist")
End If
    MsgBox ("end")
End Sub


-----------------------------------------
Get Breaking News from CNN, ABC, NBC, CBS Now.
http://www.xuppa.com/news/?link=webmail




More information about the AccessD mailing list