Monday, 1 April 2013

MCTS 70-433 Training Material

Data truncated to 255 characters with Excel ODBC driver

When you retrieve external data using the Microsoft Excel 2010 ODBC driver, fields that have more than 255 characters may be truncated to 255 characters.

Your data may be truncated to 255 characters if the first 8 records for the field(s) being truncated contain 255 or fewer characters. The Microsoft Excel ODBC driver will, by default, scan the first 8 rows of your data to determine the type of data in each column. 

Even though you can change the Rows To Scan value in the ODBC Microsoft Excel Setup dialog box to something higher than 8 (but not higher than 16) this value is not being used by Excel. The Excel ODBC driver uses the TypeGuessRows DWORD value of one of the following registry key to determine how many rows to scan in your data:

Please do the following and then try to import data using ADO . This will solve the issue.

1.       Close any programs that are running.
2.       On the Start menu, click Run. Type regedit and click OK.
3.       In the Registry Editor, expand the following key:


  • HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\12.0\Access Connectivity Engine\Engines\Excel
  • HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Access Connectivity Engine\Engines\Excel
  •  HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Jet\4.0\Engines\Excel

4.       Select TypeGuessRows and on the Edit menu click Modify.
5.       In the Edit DWORD Value dialog box, click Decimal under Base. Type value 0, for Value data. Click OK and quit the Registry Editor.

NOTE: For performance reasons, setting the TypeGuessRows value to zero (0) is not recommended if your Excel table is very large. When this value is set to zero, Microsoft Excel will scan all records in your table to determine the type of data in each column.

APPLIES TO
  • Microsoft Office Excel 2010
References-  http://support.microsoft.com/kb/189897 

Monday, 3 December 2012

VBA Excel - Stop Macro execution .

Terminating the run in your function can be done by using the keyword - "End"


Sub MySub()
    Dim x
   
    x = MyFunc("Test")
   
    MsgBox x
   
End Sub
Function MyFunc(Arg1) As Long
    If Arg1 = "Test" Then
        End
    Else
        MyFunc = 1
    End If   
End Function

Recommendation :
But using End in this way seems completely wrong. Terminating the run in your function is the wrong way.
You should pass back information via the function(s) and deal with termination in a more appropriate location.

Tuesday, 27 November 2012

The connection for viewing your linked Microsoft Excel worksheet was lost.Microsoft JET Database Engine

When you use GetObject() function to open an excel file and work on it.

Use  <.Close>  to close the file. Else we generally end up with "The connection for viewing your linked Microsoft Excel worksheet was lost.Microsoft JET Database Engine " error. 

Tuesday, 20 November 2012

Commenting VBA code using Edit Toolbar



  • In VBE Go to View - Toolbars
  • Select 'Edit' - this brings up the Edit toolbar
  • Highlight the code that you want to comment out
  • On the Edit toolbar select "Comment Block"
(There's also an "UnComment Block" to reverse this if needed)

Wednesday, 14 November 2012

RTRIM does not trim CHAR(160)

Important - LTRIM and RTRIM only remove the space character CHAR(32). They do not remove a CHAR(160) which is a non-breaking space . The strings rtrim('12345' + char(160)) and rtrim('12345' + char(32)) are not the same.


Source - http://technet.microsoft.com