Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Access VBA code editor character encoding and copy/paste

Tags:

vba

ms-access

What is the actual encoding used in Access' VBA editor? I have been searching for a concrete answer for quite a while but with no luck.

I thought it was UTF-8 but I'm not very certain.

My main issue is that when writing a query in VBA I sometimes need to test it in Access' query editor. When copy-pasting however, I lose my native characters (greek in my case) as they turn to gibberish.

I have tried pasting in a text editor and saving it as different encodings but I can never recover the original characters.

Thanks in advance.

Edit

Let me explain this a bit further:

As you can see I can write my greek characters in the VBA editor normally:

sample in vba editor

However, copying the first line in Access' query editor, I get the following:

paste in query editor

Same goes for a simple text editor:

text editor

So I am inclined to think that the problem lies inside the clipboard, due to the encoding used for the greek characters. I guess they are not Unicode, as I indeed have to make the change in the System Locale for non-unicode characters. So how are these characters saved/copied? In what encoding?

Answer

Actually this problem was solved by switching the keyboard input language to greek (EL), when copying the actual test string.

I am still not sure however, as to why that happens. If anyone can provide some insight into this, I would love to hear it.

Thanks again

like image 931
parakmiakos Avatar asked Mar 21 '14 13:03

parakmiakos


People also ask

How to copy and Paste data in VBA?

Similar to worksheet function in excel, we can also copy paste data or set of values in VBA. In normal data, we use either CTRL + C to copy a selection of data and then use CTRL + V to paste the selected data in the target cell.

What encoding is VBA?

VBA uses ANSI. So whenever doing any interaction with the OS VBA Unicode strings are converted to ANSI.


2 Answers

The VBA editor does not support Unicode characters, either for input or display. Instead, it uses the older Windows technology called "code pages" to provide support for non-ASCII characters.

So, the character encoding in the VBA editor corresponds to the code page that is used by the Windows system locale as specified in the "Regional and Language Options" control panel. For example, with my system locale set to "Greek (Greece)"

cpGreek.png

I can enter Greek characters into my VBA code

vbaGreek.png

However, if I switch my Windows system locale back to "English (United States)"

cpUS.png

and re-open my VBA project, the Greek characters have changed to the corresponding characters in the new code page

vbaUS.png

like image 186
Gord Thompson Avatar answered Sep 17 '22 07:09

Gord Thompson


If "Control Panel" -> "Regional and Language Options" -> "System Locale" is set correctly but you still suffer from this problem some times then note that while you're copying your keyboard layout must be switched to the non-English language.

This is applicable to all non-unicode-aware applications not only VBA.

Credit goes to @parakmiakos

like image 26
ndemou Avatar answered Sep 21 '22 07:09

ndemou