From: ALJ on
Hi,

I have a recordset I want to export to various different text based
formats, such as YAML and JSON. I know that it is possible to export a
rs using TransferText and have an export specification, but obviously
I need the flexibility to use different formats.

I have looked around to see if I could use ADODB.Stream but get an
error:

"Arguments are of the wrong type, are out of acceptable range, or are
in conflict with one another"

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.

Set objStream = CreateObject("ADODB.Stream")

objStream.Open
objStream.Charset = "UTF-8"
objStream.Position = 0
objStream.WriteText "Hello world"
objStream.SaveToFile "C:\Temp\testfile.txt", adSaveCreateOverwrite
objStream.Close

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Any suggestions?

ALJ
From: Tom van Stiphout on
On Mon, 22 Feb 2010 12:09:09 -0800 (PST), ALJ
<astley.lejasper(a)gmail.com> wrote:

I added one line above this code:
Dim objStream As ADODB.Stream

Then it worked for me. I have set a reference to "ActiveX Data Objects
2.8 Library".
Also make sure you have "Option Explicit" at the top of EVERY code
module. And set this to be the default in Tools > Options.

-Tom.
Microsoft Access MVP


>Hi,
>
>I have a recordset I want to export to various different text based
>formats, such as YAML and JSON. I know that it is possible to export a
>rs using TransferText and have an export specification, but obviously
>I need the flexibility to use different formats.
>
>I have looked around to see if I could use ADODB.Stream but get an
>error:
>
>"Arguments are of the wrong type, are out of acceptable range, or are
>in conflict with one another"
>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
>
>Set objStream = CreateObject("ADODB.Stream")
>
>objStream.Open
>objStream.Charset = "UTF-8"
>objStream.Position = 0
>objStream.WriteText "Hello world"
>objStream.SaveToFile "C:\Temp\testfile.txt", adSaveCreateOverwrite
>objStream.Close
>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>
>Any suggestions?
>
>ALJ
From: ALJ on
Cheers. That managed to get rid of the errors. I was using an old
library and didn't realise

However, the output won't go into the target database. I have done a
dump of the target database and it outputs umlauts, for example, as
"\u00f6" but the output I'm getting from the access database is "ö".
Having checked out the encoding using Notepad++, it appears that the
output I'm looking for is ANSI. (I'd assumed that if I set everything
to UTF8 then that would take care of it!)

Do you know how to output text from access so it gets this encoding?
("\u00f6" not "ö")

ALJ
From: Salad on
ALJ wrote:
> Cheers. That managed to get rid of the errors. I was using an old
> library and didn't realise
>
> However, the output won't go into the target database. I have done a
> dump of the target database and it outputs umlauts, for example, as
> "\u00f6" but the output I'm getting from the access database is "�".
> Having checked out the encoding using Notepad++, it appears that the
> output I'm looking for is ANSI. (I'd assumed that if I set everything
> to UTF8 then that would take care of it!)
>
> Do you know how to output text from access so it gets this encoding?
> ("\u00f6" not "�")
>
> ALJ

This link doesn't deal with Access but does deal with a similar problem.
http://objectmix.com/dotnet/368569-ascii-unicode-encoding.html. It
seems to be doing a format of the data byte by byte.
From: ALJ on
Hi Salad,

Cheers for that.

I have continued doing a lot of digging around, I found out that part
of the problem is that ADODB.stream exports as UTF-8 with BOM. I found
that if I converted it to UTF-8 without BOM then the receiving
application didn't choke.

(This was originally posted by Simon Pedersen at
http://www.imagemagick.org/discourse-server/viewtopic.php?f=8&t=12705)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
' Removes the Byte Order Mark - BOM from a text file with UTF-8
encoding
' The BOM defines that the file was stored with an UTF-8 encoding.

Public Function RemoveBOM(filePath)

' Create a reader and a writer
Dim writer, reader, fileSize
Set writer = CreateObject("Adodb.Stream")
Set reader = CreateObject("Adodb.Stream")

' Load from the text file we just wrote
reader.Open
reader.LoadFromFile filePath

' Copy all data from reader to writer, except the BOM
writer.Mode = 3
writer.Type = 1
writer.Open
reader.Position = 5
reader.CopyTo writer, -1

' Overwrite file
writer.SaveToFile filePath, 2

' Return file name
RemoveBOM = filePath

' Kill objects
Set writer = Nothing
Set reader = Nothing
End Function
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>