On screen UI, use unbound field to enter mix of ASCII and Unicode character text string for searching. On the screen, it is correct - for example "White白色". But, on VBA code, the Unicode character of the unbound filed becomes to '?' and cannot be used for searching - "White??" for the above example. How to get the mixed ASCII and Unicode string as on the screen for VBA code?
Below is my code. Me.txName is unbound text field, fiterstr is subform filter. It works, if name is all ASCII. It will search '?', if Unicode is entered.
Dim filterstr As String
If Me.txName <> "" Then
filterstr = "(Customer.Company LIKE '*" & Me.txName & "*')"
End If
Me.sfmCustomerList4Search.Form.Filter = filterstr
With Erik A. help, this question has been solved. On my question, there are two problems.
Access Msgbox does not support unicode. Erik A. has written up an unicode-compatible messagebox-implementation MsgboxW here
Data is stored ad SQL Server while Access is front end UI. SQL collation must be setup to compatible with Unicode language. Please see See Chinese collation for MS SQL.
I have a MS Access database with a column that has some strange encoding. Oddly, I am unable to copy/paste this into anything (Chrome, Word, etc), because it strips out most of the unicode characters (though not all of them). What I am wondering, is there a way to determine what type of encoding is being used here?
Somehow the program I am using is taking this column and decoding it to readable text. I converted the Access database to PostgreSQL on a Linux system, but I'm pretty sure whatever encoding is being used here did not map correctly into the PostgreSQL database. What I'm trying to do is to convert this to hex, but I cannot do it since I'm unable to copy/paste the characters out of the database.
You can open the table as a recordset. Then loop the records and convert the field to hex using a function like this:
Public Function StrToByte(ByVal strChars As String) As String
Dim abytChar() As Byte
Dim lngChar As Long
Dim strByte As String
abytChar() = StrConv(strChars, vbFromUnicode)
strByte = Space(2 * (1 + UBound(abytChar) - LBound(abytChar)))
For lngChar = LBound(abytChar) To UBound(abytChar)
Mid(strByte, 1 + 2 * lngChar) = Hex(abytChar(lngChar))
Next
StrToByte = strByte
End Function
Or create a query:
Select *, StrToByte([EncryptedFieldName]) As HexField
From tblYourTable
I have a lot of databases I would like to change their column names. These databases were designed by a team which used Portuguese words for column names. I have managed to change names with spaces but when I try to change the names for columns with Portuguese accents e.g Instalaçao, my VBScript fails with error item not found in this collection. My VBScript is for changing this column is as below.
tblName = "CONSUMIDORES"
oldColName = "[Instalaçao]"
newColName = "INSTALACAO"
Set dbe = CreateObject("DAO.DBEngine.120")
Set db = dbe.OpenDatabase(dbPath)
Set fld = db.TableDefs(tblName).Fields(oldColName)
fld.Name = newColName
This code works for other columns with spaces but for accented words it fails. I am using MS Access 2013. I am new to VBScript.
Converting the file to ANSI as suggested by Gord Thompson worked.
I'd try to get away with refering to the fields by number:
Set fld = db.TableDefs(tblName).Fields(14)
(assuming Instalaçao is the 15th field of that table).
I try to create a MySQL function to parse a given string into a version I can use in an URL. So I have to eliminate some special characters and I try to do it with a loop to keep the code simple and to not have to specify any character.
My current code is:
DECLARE parsedString VARCHAR(255);
# convert to low chars
SET parsedString = CONVERT(paramString USING latin1);
SET parsedString = LOWER(parsedString);
# replace chars with A
SET #x = 223;
charReplaceA: WHILE #x <= 229 DO
SET #x = #x + 1;
SET parsedString = REPLACE (parsedString, CHAR(#x USING ASCII), 'a');
END WHILE charReplaceA;
# convert to utf8 and return
RETURN CONVERT(parsedString USING utf8);
If I try to use my code it doesn't work. Somehow it doesn't recognize the CHAR(#x USING ASCII) part.
SELECT urlParser('aäeucn');
returns
aäeucn
If I change my code to
SET parsedString = REPLACE (parsedString, 'ä', 'a');
it somehow works and returns
aaeucn
Does anyone have any idea how to use REPLACE() with CHAR()? I don't want to specify any possible character.
You could try
REPLACE(CONVERT('aäeucn' USING ascii), '?', 'a')
When you convert international characters to ascii, all non-ascii characters are represented by a literal '?' character. Then you don't have to do the loop (so it will probably run a lot faster).
Also consider other methods of encoding international characters in URLs.
See http://www.w3.org/International/articles/idn-and-iri/
Re your comment:
If you need a character-by-character replacement, I wouldn't do it in an SQL function. MySQL functions are not efficient, and coding them and debugging them is awkward. I'd recommend fetching the utf8 strings back into your application and do the character translation there.
You didn't specify which application programming language you're using, but for what it's worth, PHP supports a function strtr() that can be used for exactly this scenario. There's even an example of mapping i18n characters to ascii characters in the manual page:
http://php.net/strtr
$addr = strtr($addr, "äåö", "aao"); // That was easy!
That solution will be far faster and easier to code than a MySQL stored function.
How is a CSV file built in general? With commas or semicolons?
Any advice on which one to use?
In Windows it is dependent on the "Regional and Language Options" customize screen where you find a List separator. This is the char Windows applications expect to be the CSV separator.
Of course this only has effect in Windows applications, for example Excel will not automatically split data into columns if the file is not using the above mentioned separator. All applications that use Windows regional settings will have this behavior.
If you are writing a program for Windows that will require importing the CSV in other applications and you know that the list separator set for your target machines is ,, then go for it, otherwise I prefer ; since it causes less problems with decimal points, digit grouping and does not appear in much text.
CSV is a standard format, outlined in RFC 4180 (in 2005), so there IS no lack of a standard. https://www.ietf.org/rfc/rfc4180.txt
And even before that, the C in CSV has always stood for Comma, not for semiColon :(
It's a pity Microsoft keeps ignoring that and is still sticking to the monstrosity they turned it into decades ago (yes, I admit, that was before the RFC was created).
One record per line, unless a newline occurs within quoted text (see below).
COMMA as column separator. Never a semicolon.
PERIOD as decimal point in numbers. Never a comma.
Text containing commas, periods and/or newlines enclosed in "double quotation marks".
Only if text is enclosed in double quotation marks, such quotations marks in the text escaped by doubling. These examples represent the same three fields:
1,"this text contains ""quotation marks""",3
1,this text contains "quotation marks",3
The standard does not cover date and time values, personally I try to stick to ISO 8601 format to avoid day/month/year -- month/day/year confusion.
I'd say stick to comma as it's widely recognized and understood. Be sure to quote your values and escape your quotes though.
ID,NAME,AGE
"23434","Norris, Chuck","24"
"34343","Bond, James ""master""","57"
Also relevant, but specially to excel, look at this answer and this other one that suggests, inserting a line at the beginning of the CSV with
"sep=,"
To inform excel which separator to expect
1.> Change File format to .CSV (semicolon delimited)
To achieve the desired result we need to temporary change the delimiter setting in the Excel Options:
Move to File -> Options -> Advanced -> Editing Section
Uncheck the “Use system separators” setting and put a comma in the “Decimal Separator” field.
Now save the file in the .CSV format and it will be saved in the semicolon delimited format.
Initially it was to be a comma, however as the comma is often used as a decimal point it wouldnt be such good separator, hence others like the semicolon, mostly country dependant
http://en.wikipedia.org/wiki/Comma-separated_values#Lack_of_a_standard
CSV is a Comma Seperated File. Generally the delimiter is a comma, but I have seen many other characters used as delimiters. They are just not as frequently used.
As for advising you on what to use, we need to know your application. Is the file specific to your application/program, or does this need to work with other programs?
To change comma to semicolon as the default Excel separator for CSV - go to Region -> Additional Settings -> Numbers tab -> List separator
and type ; instead of the default ,
Well to just to have some saying about semicolon. In lot of country, comma is what use for decimal not period. Mostly EU colonies, which consist of half of the world, another half follow UK standard (how the hell UK so big O_O) so in turn make using comma for database that include number create much of the headache because Excel refuse to recognize it as delimiter.
Like wise in my country, Viet Nam, follow France's standard, our partner HongKong use UK standard so comma make CSV unusable, and we use \t or ; instead for international use, but it still not "standard" per the document of CSV.
best way will be to save it in a text file with csv extension:
Sub ExportToCSV()
Dim i, j As Integer
Dim Name As String
Dim pathfile As String
Dim fs As Object
Dim stream As Object
Set fs = CreateObject("Scripting.FileSystemObject")
On Error GoTo fileexists
i = 15
Name = Format(Now(), "ddmmyyHHmmss")
pathfile = "D:\1\" & Name & ".csv"
Set stream = fs.CreateTextFile(pathfile, False, True)
fileexists:
If Err.Number = 58 Then
MsgBox "File already Exists"
'Your code here
Return
End If
On Error GoTo 0
j = 1
Do Until IsEmpty(ThisWorkbook.ActiveSheet.Cells(i, 1).Value)
stream.WriteLine (ThisWorkbook.Worksheets(1).Cells(i, 1).Value & ";" & Replace(ThisWorkbook.Worksheets(1).Cells(i, 6).Value, ".", ","))
j = j + 1
i = i + 1
Loop
stream.Close
End Sub