Solved

Access 2003 Importing Accented and Foreign Characters Wrong

Posted on 2014-03-13
2
362 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 49

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now