Insert Into statement not recognising non-standard characters

mikeyplop

New member
Local time
Today, 13:58
Joined
Dec 4, 2007
Messages
6
Hi all,

I have a problem with an Insert Into statement in a module in Access 2007.

I import data from another database that has poor reporting functionality and use Access to automate an export in the format our users demand. Much of the data is of a global nature and as such, the original db has many non-standard characters such as é etc.

I have no problem importing this data and keeping the original characters, but it is often nested and I use a script to flatten it so that all the nested data appears in a single cell in another table delimited by the | character, which is then exported to Excel.

For standard keyboard characters the script works fine, but I've encountered a problem with the text "Muséum national d'Histoire naturelle - Département des Milieux et Peuplements Aquatiques".

When the script gets to this line it doesn't append the data to the new table, it just leaves it blank and moves to the next record. All other records work fine.

I have debugged in the immediate window and I find that the variable I have declared is actually holding the data, but that's as far as it gets, it won't insert it into the other table. I should point out that the field type for both the originating table and the table the data is pasted into are memo. I know memo is buggy, but I have no choice as the length of the string in the original db can be longer than 255 characters and the users need the full info.

I have tried:
1. Changing the variable type from string to variant. No response.
2. Adding " to each end in the hope that it might deal with it as a fixed string. No luck.
3. Using the Left function as I thought it might have something to do with memo data types and I have seen some solutions for other memo problems not strictly like my problem that use the Left function to trick Access.

I haven't pasted the code as it is working fine normally, just bugging with unusual data, so I don't think the problem is there, more with the way Access handles the data.

Any help would be greatly appreciated.

Kind regards,

Michael
 
Michael,

You didn't post your code, but I'll bet the --> d'H

The single-quote might be confusing the SQL parser.

Wayne
 
Thank you Wayne!!!

I took the data back to just before the ' and it worked fine for the remaining text.

Many thanks for the prompt reply.

Kind regards,

Michael
 
For anyone who's interested, the solution was to find and replace the apostrophe in any text that was parsed so that the SQl could insert it properly.

Thus:

strSummaryData = rst!SummaryData

If InStr(1, strSummaryData, Chr(39)) > 0 Then
strSummaryData = Replace(strSummaryData, Chr(39), Chr(39) & Chr(39))
End If

I set the variable strSummaryData to the data from the recordset and then checked to see if it had an apostrophe in it (ie. Chr(39)). If it did it was replaced by 2 apostrphes together, which SQl then treats as one.

This was not my idea by the way, it's all thanks to posts on various forums, so many thanks to the origianl posters.

Regards,

Michael
 
For anyone who's interested, the solution was to find and replace the apostrophe in any text that was parsed so that the SQl could insert it properly.

Thus:

strSummaryData = rst!SummaryData

If InStr(1, strSummaryData, Chr(39)) > 0 Then
strSummaryData = Replace(strSummaryData, Chr(39), Chr(39) & Chr(39))
End If

I set the variable strSummaryData to the data from the recordset and then checked to see if it had an apostrophe in it (ie. Chr(39)). If it did it was replaced by 2 apostrphes together, which SQl then treats as one.

This was not my idea by the way, it's all thanks to posts on various forums, so many thanks to the origianl posters.

Regards,

Michael

Nice find. I'm a little old school and the instring/replace function weren't around during my initial development years so I forgot all about these functions. Sure saved me a lot of long hand coding for my particular situation.

Again this site comes through even though this is quite an old thread.

cheers!!
 

Users who are viewing this thread

Back
Top Bottom