Re: copying table structure in VBA

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: George Nicholson (JunkGeorgeN_at_msn.com)
Date: 03/01/05


Date: Tue, 1 Mar 2005 11:38:14 -0600

When unspecified, the default CursorType for Recordset.Open in ADO is
forward-only.

The Help entry for ADO Recordcount states that the property will return -1
for forward-only cursors.

Try adding the following (or one of its variants) before rs.Open:
    rs.CursorType = adOpenStatic '(or adOpenDynamic or adOpenKeyset)

HTH,

-- 
George Nicholson
Remove 'Junk' from return address.
"ChrisB" <ChrisB@discussions.microsoft.com> wrote in message 
news:4B3C7BD3-C344-4D8A-B590-3F39337F9FF6@microsoft.com...
> Hi. I'm hitting my head into the ground here.
> Maybe the biggest problem is Access 2000, but I have no choice in the
> version at this time. anyway, the basic question is how do I connect an
> ADODB.Recordset to the current Access database? (please read last 
> paragraph
> for code sample if that's all you will answer)
>
> I need to copy a table structure. At first, in code, I made a copy of a
> table to another name. Then I "delete * from newtable" and proceeded to
> "insert ..." to populate the table. The point is that I have multiple 
> insert
> statements that put data in a specific order, too complex for just 1 
> "order
> by" clause. While debugging, it always works perfectly. While running 
> without
> breaking, the order of the data inserted is always RANDOM!! I'm thinking 
> it
> has to do with maybe that data is never REALLY deleted from the tables, 
> that
> it's only marked, and that inserting "un marks it?" Don't know. Tried 
> putting
> in delays.. didn't help.
>
> so I now am trying to copy the structure by code. Using DAO I have
> problems.. like if the field type is 20 (which is supposed to be "Number" 
> but
> not sure what type=20 really is) the code spits out an error when doing
> something like: tDest.Append( theField )
>
> So trying ADO. But I can't get passed a very simple connection problem. 
> Can
> anyone answer this one? This is what I have for the code, and it simple
> doesn't work. No errors, but rs.RecordCount is always -1 no matter what 
> query
> I run:
>    Dim rs As ADODB.Recordset
>    Set rs = New ADODB.Recordset
>    Dim cnn As ADODB.Connection
>    Set cnn = New ADODB.Connection
>    cnn.ConnectionString = CurrentProject.Connection
>    Call cnn.Open
>    rs.ActiveConnection = cnn
>    'rs.ActiveConnection = CurrentProject.BaseConnectionString
>    'rs.ActiveConnection = CodeProject.Connection
>    Call rs.Open("select * from " & sSourceTable)
>
>    If rs.RecordCount > 0 Then
> ' it never gets here.. recordCount is always -1
> ' And YES, there IS data in this table! :) Any query I run will result 
> in -1
>        rs.MoveLast
>        rs.MoveFirst
>    End If
> 


Relevant Pages

  • Re: getting sheets when using ADOX Catalog to read Excel
    ... uses ADO to get a list of worksheet names. ... I know how to do it with Excel ... Dim cnn As ADODB.Connection ...
    (microsoft.public.access.externaldata)
  • Re: better search method
    ... Rather than ADOX, you'd find ADO more useful to actually *retrieve* the data. ... > The code below reads the names of all Sheets in a Workbook ... Dim cnn As New ADODB.Connection ... Dim tbl As ADOX.Table ...
    (microsoft.public.excel.programming)
  • Re: Select mit Alias
    ... Egal, welchen Wert ich für den Cursortype einsetze, ... Ich nehme mal an, das liegt am Wesen der Access-DB, die damit ... korrigiert ADO den Typ auf einen realisierbaren ...
    (microsoft.public.de.vb.datenbank)
  • Re: "Row handle referred to a deleted row or a row marked for deletion" in BetterADO
    ... > I am not deliberately using Bookmarks so they must be being set by ADO. ... > need clUseClient. ... > CursorType but BetterADO defaults to ctStatic. ...
    (borland.public.delphi.database.ado)
  • RE: how do I run queries in access on external data?
    ... >> Hi lisa, ... >> I think you should use ado to connect to excel. ... >> Dim rs As ADODB.Recordset ... >> Dim cnn As ADODB.Connection ...
    (microsoft.public.access.formscoding)