Convert Windows Char Set to Cyrillic - ms-access

I have a set of tables from a client that are supposed to be Cyrillic, but I guess the original coding was wrong or not set. All the text is gibberish.
If I past the text into an html page and set the encoding to Cyrillic-1251, I see the text as it should be.
Before: Ñèíèöûí À.Â.
After: Синицын А.В.
I've been looking for a VBA solution to convert the text in the tables without success. I thought this would be quick & easy, but so far no luck.
I'm running Win 7 with Access 2010
If you don't know Access, but have any VBA function to do this, I can adapt it to my needs.
Any help would be appreciated.

One possible way to solve the problem would be to export the table to CSV as code page 1252 ("ANSI") and then import it as code page 1251. I just tried that and for an existing table named [OldTable]
the following VBA code
Option Compare Database
Option Explicit
Sub DiskBounce()
Const tempFilePath = "C:\Users\Gord\Desktop\foo.csv"
DoCmd.TransferText _
TransferType:=acExportDelim, _
TableName:="OldTable", _
FileName:=tempFilePath, _
HasFieldNames:=True, _
CodePage:=1252
DoCmd.TransferText _
TransferType:=acImportDelim, _
TableName:="NewTable", _
FileName:=tempFilePath, _
HasFieldNames:=True, _
CodePage:=1251
Kill tempFilePath
End Sub
produced the following [NewTable]

Related

Rename excel file depending on Access Table first field

By using VBA Access ,I want to copy excel and rename it depending on Table first field.
In below example,
For example, instead of using fixed name like:
FileCopy "C:Documents\Folder\CurrentFile.xlsx", "C:\Documents\New Folder\NewFile.xlsx"
I want to use:
FileCopy "C:Documents\Folder\CurrentFile.xlsx", "C:\Documents\New Folder\NewFile" & [Table1]![Feild1] & ".xlsx"
Your question is unclear, but if [Table1]![Field1] returns the string to replace only CurrentFile then you could use:
FileCopy "C:\Documents\Folder\CurrentFile.xlsx", _
"C:\Documents\Folder\" & [Table1]![Field1] & ".xlsx"
...so:
C:Documents was missing a \
NewFile" & [Table1]![Feild1] & ".xlsx" was also missing a \
[Feild1] may need to be spelled [Field1] (unless the misspelling was intentional)

Access VBA not recognizing range in Excel spreadsheet

I am having a most frustrating time time with the DoCmd.TransferSpreadsheet method. I have a workbook with multiple worksheets in which users are updating data and I have a script that puts all the records back into a single sheet, links the spreadsheet, and updates the data in my Access DB. My problem is in the Range parameter. I pass the following string and get the following error:
DoCmd.TransferSpreadsheet TransferType:=acLink, SpreadsheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:=linkSheet, fileName:=Wb.Path & "\" & Wb.name, _
HasFieldNames:=True, Range:="AccessUpdate!updateTable"
The Microsoft Access database engine could not find the object 'AccessUpdate$updateTable'. Make sure the object exists and that you spell its name and the path name correctly. If 'Access_Update$updateTable' is not a local object, check your network connection or contact the server administrator.
I can't seem to understand why it substitutes the dollar sign for the bang. Any other help in understanding how to specify the range would also be appreciated.
Thanks!
I know this is an year old question but it is an almost timeless problem.
I'm trying to do the same from the Excel side and bumping into the same problem. Access switching the sheet separator "!" for "$"
I found that this is a bug from Access 2000 that was never corrected. Or better, it was partially corrected at some point. So depending on your Access build and the size of the range [yes, size, since this is a bug from Access 2000] the solutions provided by Cisco or HansUp will work.
Another sources explaining the problem and a similar solution is provided by the MS$ themselves
https://answers.microsoft.com/en-us/office/forum/office_2007-access/transferspreadsheet-error-3011-can-not-file-sheet/980b2dc1-9ee1-4b3e-9c3c-a810f1428496
with the help of Bob Larson Former Access MVP (2008-2010) [see his very last post]
Now, if your range is on a different sheet with more than 65536 rows, this bug will come back.
See here for reference
Funny enough, if this is Sheet1 [yes, index 1 of all sheets] it will work with any range size. But any other sheet it wil fail.
This was my original range: BASE!A2:X68506, named REF_ACCESS. BASE is my Sheet5. Access 2010 & Excel 2010
I tried ActivateSheet, assign to string inside command, assign to string outside command, replace(,"$","!""), nothing worked. Even on Office 2016 from a friend
If I use "BASE!A2:X64506", it works. If I use "A2:X68506", Access assumes Sheet1 and works. Attention that all ranges do not have "$", but I guess you already know that
My last test was something like this monster
DoCmd.TransferSpreadsheet TransferType:=acImport, SpreadsheetType:=9, TableName:="TEST", Filename:=ThisWorkbook.FullName, HasFieldNames:=False, Range:=Worksheets("BASE").Name & "!" & Replace(Left(Worksheets("BASE").Range("REF_ACCESS").Address, Len(Worksheets("BASE").Range("REF_ACCESS").Address) - 1), "$", "")
A test that using my range within the 65536 row limit [6553 to be precise] would work. And it did.
So I see solutions with only two options for now. Either copy your range to Sheet1 or another sheet, as RyanM did, or divide your range in multiple DoCmd with 65536 rows.
I know it is long. Sorry, this was 2 full days looking for an answer without any real solution. I hope this helps other people with the same problem.
I tried multiple methods for getting around this without making major modifications to my code but with no avail. I did come up with a solution but it is rather resource intensive and messy. However, in case someone has a similar issue, I will post it here. I wound up separating my update sheet into it's own file from the rest of the workbook and linking that file. This prevented Access from trying to link a different sheet and got me around the whole Range issue. I know it's not elegant or efficient but it worked. If I figure out a cleaner way I'll post it here.
Set xl = Wb.Parent
xl.ScreenUpdating = False
xl.DisplayAlerts = False
strFile = mypath & "\TempIss.xlsx"
For i = 1 To Wb.Worksheets.count
If InStr(1, Wb.Worksheets(i).name, "Update", vbTextCompare) > 0 Then
tableId = i
Exit For
End If
Next i
If tableId = 0 Then
MsgBox "This workbook does not seem to have the necessary worksheet for updating " & _
"the Participant Issues Log in Access.", vbInformation, "Uh oh..."
Exit Function
Else
Set upWs = Wb.Worksheets(i)
upWs.Select
upWs.Copy
xl.ActiveSheet.SaveAs fileName:=strFile
xl.ActiveWorkbook.Close
Call rmSheet(Wb, "AccessUpdate")
xl.ScreenUpdating = True
linkSheet = "tempIssLog"
DoCmd.TransferSpreadsheet TransferType:=acImport, SpreadsheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:=linkSheet, fileName:=strFile, _
HasFieldNames:=True
Kill (strFile)
If the range is a named range (in Excel) follow the instruction above (HansUp comment).
If the range is defined in MS-Access be sure to pass a string (something like "A1:G12") and not the control name.
Dim StrRange as variant
Dim NameofMySheet as string
NameofMySheet = "xxxxxx" ' <- Put here the name of your Excel Sheet
StrRange = NameofMySheet & "!" & "A1:G12"
DoCmd.TransferSpreadsheet TransferType:=acLink, SpreadsheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:=linkSheet, fileName:=Wb.Path & "\" & Wb.name, _
HasFieldNames:=True, Range:= StrRange
Note 1: StrRange with no quotes!

Using FileSystemObject in Access VBA

I'm using Access 2010, and here is screenshot from my reference libraries and avalible FileSystemObject methods from within Access VB IDE:
When I initiate this object I can't seem to be able to access familiar methods, as I get exception with this example debug result:
I also used explicit declarations and initialized variables to get same results.
Any ideas what may be wrong?
To replay on #4dmonster comment, this is the actual array:
For Each p In Split("f:\temp\test\op1\gev_final_1.xlsx;f:\temp\test\op1\gev_final_2.xlsx;f:\temp\test\op1\gev_final_3.xlsx;f:\temp\test\op1\gev_final_4.xlsx;" & _
"f:\temp\test\op1\gev_final_5.xlsx;f:\temp\test\op1\gev_final_6.xlsx;f:\temp\test\op1\gev_final_7.xlsx;f:\temp\test\op2\gev_final_8.xlsx;" & _
"f:\temp\test\op2\gev_final_9.xlsx;f:\temp\test\op2\gev_final_10.xlsx;f:\temp\test\op2\gev_final_11.xlsx;f:\temp\test\op2\gev_final_12.xlsx;" & _
"f:\temp\test\op2\gev_final_13.xlsx;f:\temp\test\op3\gev_final_14.xlsx;f:\temp\test\op3\gev_final_15.xlsx;f:\temp\test\op3\gev_final_16.xlsx;" & _
"f:\temp\test\op3\gev_final_17.xlsx;f:\temp\test\op3\gev_final_18.xlsx;f:\temp\test\op3\gev_final_19.xlsx;f:\temp\test\op4\gev_final_20.xlsx;" & _
"f:\temp\test\op4\gev_final_21.xlsx;f:\temp\test\op4\gev_final_22.xlsx;f:\temp\test\op4\gev_final_23.xlsx;f:\temp\test\op4\gev_final_24.xlsx;" & _
"f:\temp\test\op5\gev_final_25.xlsx;f:\temp\test\op5\gev_final_26.xlsx;f:\temp\test\op5\gev_final_27.xlsx", ";")
The problem here is that GetFolder() is being passed a string containing the full path to a file and it is rightfully complaining that such a folder does not exist. If you want to extract the folder in which a particular file resides then you could use something like
fso.GetFile("C:\Users\Public\Database1.accdb").ParentFolder

Access importing wrong columns

Help! Access is importing wrong columns from a csv file. There are no commas in the csv and there should not be any spaces like (space)(space), but just (space). I'm ending up with '' in the SERIAL_NR header, but in the actual csv there are values.
This is giving me 1000 extra rows. Is there anything else to check for?
It's sneaky and underhanded, but the alt+enter character [chr(10)] was included in a few of the cells. I used the following vba code to get rid of it.
sub cleaner()
Dim enterchar as string
enterchar = chr(10)
activesheet.usedrange.Replace What:=enterchar, Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
end sub
Pretty nifty for prepping a csv for import into Access. I've created an add-in for cleaning csv's (eliminating duplicates, special char's, etc.) if anyone's interested I'll post.
Thanks all!

Microsoft Access TransferText function: problem with codepage

I inherited a huge, bulky MS Access database and am assigned to solve a problem in it. The problem is as follow...
System A exports its data to a pipeline-delimited .txt file. The files has special characters working correctly, for example the value "Müller" shows when opening this file in notepad or Excel.
Next, the Access DB imports the .txt file and stores the result in an internal employees table. The last name field is of data type "memo". The method to import data from the .txt file to MS Access is as follow:
Call DoCmd.TransferText(acImportDelim, _
"tblEmployees", _
"tblEmployees", _
me.txtImportFile, _
True)
After running this import and viewing the employees table I noticed that names with special characters are screwed up. "Müller" becomes "M├⌐ller" for example. I investigated some online help and found out that can include a "codepage" parameter in the TransferText call, so I set it to 65001 (which appearantly is the codepage for unicode):
Call DoCmd.TransferText(acImportDelim, _
"tblEmployees", _
"tblEmployees", _
me.txtImportFile, _
True, _
, _
65001)
Now that I have ran the import script again, I see no difference whatsoever, the special characters are still misformed. I'm running out of steam so I hope one of you has some advise on how to resolve this...
Both versions of your TransferText operation are using a SpecificationName named tblEmployees. What Code Page is specified in that Specification?
Try importing the text file manually. Choose "Advanced" from the Import Text Wizard. Then select Unicode in the Code Page list box. You may need to test with different Code Page selections until you find which one imports your text correctly.
Which ever Code Page selection works, save your choices as a specification and use it in your TransferText command, without supplying a separate CodePage parameter.
Using CodePage=1200 (msoEncodingUnicodeLittleEndian) solved the issue in my case.
there is an unicode list to use in VBA:
http://msdn.microsoft.com/en-us/library/office/aa432511(v=office.12).aspx