Results 1 to 4 of 4

Thread: I feel really stupid, but Access/ADO question

  1. #1

    Thread Starter
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244

    I feel really stupid, but Access/ADO question

    I have an import routine for an Access table written in Access VBA. It should just take the table of a specified file and run its data through ADO, update and voila.

    I feel really dumb, but shouldn't I be able to get an updatable RS from one DB, change the ActiveConnection, call UpdateBatch and have it save to the new DB? I've tried a bunch of different ways and nothing. No update. Even though there's a recordcount that's the same. What am I missing.
    VB Code:
    1. Private Sub ImportTable_Generic(ByVal ImportPath As String, ByVal TableName As String)
    2. '    DoCmd.runsql "Delete * from " & TableName & ";", True
    3. '    DoCmd.TransferDatabase acImport, "Microsoft Access", _
    4. '        ImportPath, acTable, TableName, _
    5. '        TableName, False
    6.  
    7.     On Error GoTo err_ImportTable_Generic
    8.  
    9.     Dim adoRSSource As New ADODB.Recordset
    10.     Dim adoRSDest As New ADODB.Recordset
    11.    
    12.     Dim adoConSource As New ADODB.Connection
    13.    
    14.    
    15.     Dim strSQL As String
    16.     strSQL = "SELECT * FROM " & TableName
    17.    
    18.     adoConSource.CursorLocation = adUseClient
    19.     adoConSource.CommandTimeout = 300
    20.     adoConSource.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ImportPath
    21.    
    22.     adoRSSource.CursorLocation = adUseClient
    23.     adoRSSource.Open strSQL, adoConSource, adOpenForwardOnly, adLockBatchOptimistic, adCmdText
    24.    
    25.     adoRSDest.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CurrentProject.Path & "\" & CurrentProject.Name
    26.     'adoRSDest.ActiveConnection = CurrentProject.Connection
    27.     adoRSDest.Open adoRSSource
    28.     adoRSDest.UpdateBatch
    29.    
    30.     DoCmd.Beep
    31.    
    32. exit_ImportTable_Generic:
    33.     If Not (adoRSSource Is Nothing) Then Set adoRSSource = Nothing
    34.     If Not (adoRSDest Is Nothing) Then Set adoRSDest = Nothing
    35.     If Not (adoConSource Is Nothing) Then Set adoConSource = Nothing
    36.     Exit Sub
    37. err_ImportTable_Generic:
    38.     Debug.Print Err.Number; Err.Description
    39.     MsgBox Err.Number & vbCrLf & Err.Description
    40.     Resume exit_ImportTable_Generic
    41. End Sub
    Watch. It'll be something really obvious, too.

  2. #2

  3. #3

    Thread Starter
    Addicted Member WALDO's Avatar
    Join Date
    Aug 2002
    Location
    Swing of Prussia, PA
    Posts
    244
    I'm a schmack! We figured out what it was. The rows we were attempting to update had autonumbers and were already deleted before we tried to import the tbl. It updated perfectly, just had no rows to show for it.

    Oh well.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Well smack. :doh:

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