Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Update table in mdb (2000 sr-1)

    how to send this rage from sheet to a table of Access?

    Example:
    dbname:mio_db
    table name:mia_tabella
    fileds name:filed1, filed2, ......filed15

    note: filed15 is refered to the date of elaboration
    the value of this range is a result of a daly macro, in this case if i start the macro to update the record in access copy the value from excel sheet up the old set of value already imported...



    naturally

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Update table in mdb (2000 sr-1)

    Set a reference to the Microsoft ActiveX Data Objects 2.1 Library - you've used that before.

    Create a macro like this:

    Sub ExportToDb()
    Dim strConnection As String
    Dim cnn As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim i As Integer

    On Error GoTo ErrHandler

    ' Set connection string
    strConnection = "..."
    ' Open connection
    cnn.Open strConnection
    ' Open recordset
    rst.Open "mia_tabella", cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
    ' Add new record
    rst.AddNew
    ' Set the fields
    For i = 0 To 14
    rst.Fields(i) = Worksheets("Foglio1").Cells(1, i + 2)
    Next i
    ' Save the record
    rst.Update

    ExitHandler:
    On Error Resume Next
    ' Close the recordset
    rst.Close
    ' Close the connection
    cnn.Close
    ' Destroy variables
    Set rst = Nothing
    Set cnn = Nothing
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

    You should set the connection string to connect to mio_db.mdb. You know how to do that.

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Update table in mdb (2000 sr-1)

    Hans as usual tks!
    Excellent code and excellent comment in code, sure is good for me your comment in code!
    Sal.

    note:sorry for delay;-)

Posting Permissions

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