[AccessD] Replace Function

Gustav Brock gustav at cactus.dk
Tue Oct 21 10:01:55 CDT 2003


Hi Oleg

> I still get byRef argument type mismatch :((
> What does it mean ?

What it says.
Your array returns a Variant while Replace01() probably needs a
String.
Try this:

  .. Replace01(CStr(aRecord(2)) ..

/gustav


> ------
> 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) & "','" & Replace01(aRecord(2),
> "'", "''") & "','" & Replace01(aRecord(3), "'", "''") & "','" &
> Replace01(aRecord(4), "'", "''") & "')"
>        strSQL = "INSERT into Table1Testing(a, b, c,d,e) Values(" & "'" &
> aRecord(0) & "','" & aRecord(1) & "','" & Replace(aRecord(2),
> Chr(39), Chr(39) + Chr(39)) & "','" & Replace(aRecord(3), Chr(39),
> Chr(39) + Chr(39)) & "','" & Replace(aRecord(4), Chr(39), Chr(39) +
> Chr(39)) & "')"

>         Debug.Print strSQL
>         CurrentDb.Execute (strSQL)

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




>> Hi Oleg
>>
>> Try this:
>>
>>   Replace(MyRecord(0), Chr(39), Chr(39) + Chr(39))
>>
>> /gustav
>>
>>
>>> Gustav, I get an error message 'automation type not supported in
>>> Visual Basic', but in any case speed is not #1 issue, I am much more
>>> concerned that it doesn't work for words with apostraphe, and when I
>>> write Replace(MyRecord(0),"'","''") I get error ByRef mismatch....



More information about the AccessD mailing list