Results 1 to 16 of 16

Thread: ADO Connection

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,535

    ADO Connection

    I have a connection between Excel and Access which is/was working fine, so I thought, but I've just discovered my recordset items are no longer than 256 characters.

    Please don't tell me this is a max limit, and much of my stuff is longer.

    My connect string is

    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & theName & ";" & _
    "extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"

    and Cursor types

    rx.Open sql$, cnn, adOpenStatic, adLockReadOnly

    Can I get round this anyhow - please? !

    Thanks, ABB

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,535

    Re: ADO Connection

    Ok I've done a bit more work on this and can maybe improve the question. (Assuming this is the right Forum for it ??)

    If I connect to Access, from Excel, I can apply a query and the resulting recordset elements will contain all the data. (>255 chars if the Access table field is Memo)

    However, the reverse - Access connecting to Excel has a limit of 255 characters.

    These are my findings. Am I right so far ?

    Is there any way for Access to get > 255 chars from Excel ?

    Thanks for any answers, ABB

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: ADO Connection

    let's back up for a moment... how are you verifying that you're only getting 256 characters?

    In other words, how are you checking your data?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,535

    Re: ADO Connection

    Hi techgome,

    In the debug window in Access. I print rx(0) and check it against what's in Excel.
    I also pasted it into ? len("....") to get the actual count.

  5. #5
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: ADO Connection

    This problem comes into play because the ODBC driver only checks the first 8 or so rows of data, and if none of those rows are > 255 then the field is created with that restriction. There is a fix for it.

    http://support.microsoft.com/kb/189897/

    I personally don't find connecting to excel sheets that way very appealing.

  6. #6
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: ADO Connection


  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,535

    Re: ADO Connection

    Hi dmaruca,

    Intriuging read and nicely imformative. Thanks for the links. It's given me some ideas.

    I'm going to apply the registry change as outlined but I'll be surprised if it works. If DWORD specifys
    the number of rows to check and max is 16, and you don't have one cell with >255 in the first 16 rows.... no change? It does recommend NOT using 0 to check all rows.

    I'm tempted to force one to > 255 and see what happens. The best thing is Excel can read everything from Access, so the problem is just one-way.

    >don't find connecting to excel sheets that way very appealing

    I don't know any other way. But this is working and if this 255 limit can't be got around, I'll get the data into Access soeme other way !

    Regards, ABB

  8. #8
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: ADO Connection

    The preferred method would be to either use docmd.transferspreadsheet from access or open the workbook using excel automation and assign the data to an array like so

    Code:
    arrayVariant = sht.Range("A1:Z100").Value2
    use whatever range suits you. arrayVariant is now a 2 dimensional array that you can feed into anything you want. Cheers.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,535

    Re: ADO Connection

    dmaruca I don't know how to open "using excel automation' .
    Had a try with docmd.transferspreadsheet and recieved Run-time error '3170':
    Couldn't find installable ISAM.

    Googled for a fix for this and found dozens of people asking but not ONE answer or solution. Isn't that soooo annoying!!?? It must be on here somewhere - off to search more!

  10. #10
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: ADO Connection

    Using excel automation means opening up an Excel.Application and controlling it.

    http://support.microsoft.com/kb/219151

    The ISAM error could be related to the argument you supplied to the spreadsheet type (2nd paramater).

    http://support.microsoft.com/kb/90111

    I couldn't provide any more help without more specific questions or examples of what you're doing.

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,535

    Re: ADO Connection

    Fair enough, thanks dmaruca but I'm just about ready to flag it! There's nothing that says what 'automation' is, without that knowledge the article can be read but is meaningless. Microsoft Excel 11.0 Object Library is ticked in the References FWIW.

    It's unclear if the ISAM error is a result of Excel or Access. Msexcl40.dll is present and it's path is correct in the Registry. Running "Regsvr32 c:\Windows\system32\msexcl40.dll" reports it suceeded. But the error remains. It does compile without complaint.

    The next suggestion was to re-install. But reinstall what ?

    There's just the one line in Access (97) and Eccel is Ofice 2003.

    Code:
    DoCmd.TransferSpreadsheet acImport, , "tblXferTest", "E:\00Latest\ADO999886mw.xls", True, "A1:G12"
    I still intend to try a 'dummy' cell of > 256 chars and see what happens with the ADO connection.
    Regards, ABB

  12. #12
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: ADO Connection

    Automation is just a term for controlling excel using code. that article gives perfect example of that.

    I can't speak any further about the ISAM error since I don't have 97. Try saving your workbook as an earlier version and try that. Other than that...

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,535

    Re: ADO Connection

    I open Excel and have various macros that are used. Is that 'automation' ? The article kicked off with 'binding' and how there are two kinds.... so I was a bit lost ! But anyway your DoCmd.TransferSpreadsheet method looks more promising. Whan you said you didn't have 97 I remembered I have Access 2003 (but am more familiar with 97) so I tried the command in that and it almost worked. No ISAM Error but now there's Run-time error '2391':

    Field 'F1' doesn't exist in destination table 'tblXferTest.'

    Which is quite true but it doesn't exist in Excel either. And setting 'HasFieldNames' to either True or False doesn't fix it.

    This seems to conflict with MS saying set it True 'to use the first row of the spreadsheet as field names'. The first Excel row does have Field Names and they're the same as the Field names in Access.

    Must you rename all the Access Fields to F1, F2, F3 etc? And I suppose after the transfer you could rename them back, but that seems silly.

    Do you get the same problem ?

    Thanks, ABB

  14. #14
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: ADO Connection

    The transferspreadsheet method definitely isn't perfect It looks like it's trying to pick up junk data.

    One way around that is to transfer it into a new table, append the columns you want into your existing table, and then to delete the new table.

    If you want you can zip up your spreadsheet and post it and I'll help you get it input if nothing seems to work. Good night!

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,535

    Re: ADO Connection

    I open Excel and have various macros that are used. Is that 'automation' ? The article kicked off with 'binding' and how there are two kinds.... so I was a bit lost ! But anyway your DoCmd.TransferSpreadsheet method looks more promising. Whan you said you didn't have 97 I remembered I have Access 2003 (but am more familiar with 97) so I tried the command in that and it almost worked. No ISAM Error but now there's Run-time error '2391':

    Field 'F1' doesn't exist in destination table 'tblXferTest.'

    Which is quite true but it doesn't exist in Excel either. And setting 'HasFieldNames' to either True or False doesn't fix it.

    This seems to conflict with MS saying set it True 'to use the first row of the spreadsheet as field names'. The first Excel row does have Field Names and they're the same as the Field names in Access.

    Must you rename all the Access Fields to F1, F2, F3 etc? And I suppose after the transfer you could rename them back, but that seems silly.

    Do you get the same problem ?

    Thanks, ABB

  16. #16
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: ADO Connection

    @abb, see tutorial for automating office applications, including excel
    in the faq thread at the top of this forum

    vb Code:
    1. set oexcel = createobject("excel.application")
    2. set wb = oexcel.workbooks.open("somepath\workbook.xls")
    you can now work with the wb object, though often more useful to have sheet object
    vb Code:
    1. set sht = oexcel.workbooks.open("somepath\workbook.xls").sheets(1)  ' sheet index or name
    2. arr2d = sht.range("a1:f99")
    arr2d is a 2 dimensional 1 based, variant array and would contain the values of all the cells in the specified range
    you can then use the array to populate records in access
    if finished with excel
    vb Code:
    1. wb.close false ' not to prompt to save changes and discard
    2. set wb = nothing
    3. oexcel.quit
    4. set oexcel = nothing
    nearly all excel macro code can be adapted to work in automation from other applications, but be extra careful if trying to work with selection object
    Last edited by westconn1; Jan 23rd, 2011 at 05:50 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width