Solved

Access 2003 Importing Accented and Foreign Characters Wrong

Posted on 2014-03-13
2
367 Views
Last Modified: 2014-05-15
Hi,

I have an import procedure and have for the last 2 years been trying to amend an issue with foreign characters, these get tuned into rubbish text strings on import using the below code

Dim strImpFile As String
    Dim strDecrypt As String
    Dim strComplete As String
    Dim strPrefix As String
    Dim fs, a
    Dim strLine As String
    Dim strSQL As String
    
    'MsgBox strFile
    
    strPrefix = gGetSitePrefix(strFile)
    strDecrypt = Me.OrderPickup
    strComplete = gGetOrderBackup(strPrefix)
    strImpFile = strDecrypt & strFile

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.OpenAsTextFile(strImpFile, 1, False)
    Do While a.AtEndOfStream <> True
        strLine = a.ReadLine
        strLine = Replace(strLine, "'", "")
        strSQL = "INSERT INTO tblImport (NetOrderNo,[Date],[Time],OrderStatus,Email,FirstName,Surname,CompName,Addr,Addr2,Town,County,Postcode,Country,DelName,DelSurname,DelCompName,DelAddr,"
        strSQL = strSQL & "DelAddr2,DelTown,DelCounty,DelPostcode,DelCountry,CustTele,CustDayTele,CustFax,PayMethod,CardType,CardName,CardNumber,ValidToM,ValidToY,ValidFromM,ValidFromY,"
        strSQL = strSQL & "Issue,CVV,Referrer,OrderNote,FindUs,Details,OtherComms,DeliveryDetails,WebsiteDetails,HoldingDate,ProductRef,ProducDesc,Price,Qty,Postage,Newsletter,[BoldNote],[BoldNote1],[BoldNote2],[GiftWrap],[ProductGroupID],[TypeID],[EstShipDate],[ShippingService]) SELECT "
        
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'web ord id
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'date
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'time
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & Left(strLine, InStr(strLine, "|") - 1) & "," 'orderstatus
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbLowerCase) & "'," 'email
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'first
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'last
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'comp
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'add1
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'add2
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'town
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'county
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'postcode
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'country
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'del first
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'last
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'comp
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'add1
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'add2
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'town
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'county
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'postcode
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'country
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'tel
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'fax
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'mob
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & Left(strLine, InStr(strLine, "|") - 1) & "," 'pay meth
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'card type
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & StrConv(Left(strLine, InStr(strLine, "|") - 1), vbProperCase) & "'," 'card name
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & gOnlyNumeric(Left(strLine, InStr(strLine, "|") - 1)) & "'," 'card no
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'exp m
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'exp y
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'val m
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'val y
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'iss
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'cvv
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'ref
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'order note
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'find us
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'details
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'other comms
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'DeliveryDetails
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'WebsiteDetails
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'HoldingDate
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'prod id
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'desc
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & Left(strLine, InStr(strLine, "|") - 1) & "," 'price
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & Left(strLine, InStr(strLine, "|") - 1) & "," 'qty
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & Left(strLine, InStr(strLine, "|") - 1) & "," 'del charge
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'Newsletter
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'Bold Note
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'Bold Note 1
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'Bold Note 2
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'Gift Wrap
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "'" & Left(strLine, InStr(strLine, "|") - 1) & "'," 'Product Group ID
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        'MsgBox (strLine)
        
        
        strSQL = strSQL & "" & Left(strLine, InStr(strLine, "|") - 1) & "," 'Product Group ID]
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        strSQL = strSQL & "#" & Left(strLine, InStr(strLine, "|") - 1) & "#," 'Product Group ID]
        strLine = Right(strLine, Len(strLine) - InStr(strLine, "|"))
        
        'MsgBox (strLine)
        strSQL = strSQL & "'" & strLine & "';" 'Type ID
        
       
        
        
        'MsgBox strSQL
        
          DoCmd.RunSQL strSQL
        
        strLine = ""
    
    Loop
    a.Close
    Set a = Nothing

Open in new window


Any ideas on how I can stop it?

Cheers
Karl
0
Comment
Question by:Kbba04527
2 Comments
 
LVL 15

Expert Comment

by:gplana
ID: 39926092
I don't know which character encoding is your file from you are importing this data. However, I think it will be useful for you to look at this link:

http://office.microsoft.com/en-us/access-help/strconv-function-HA001228915.aspx

Which explains about strConv function to convert from different character encodings.

Hope it helps. Regards.
0
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 39926093
Use a DAO recordset and .AddNew and not "SQL INSERT ..":

http://www.experts-exchange.com/Database/MS_Access/Q_28381863.html#a39909771

It will also run a magnitude faster.

/gustav
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question