Results 1 to 2 of 2

Thread: VBA: Reference

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Mar 2019
    Posts
    1
    Location

    VBA: Reference

    I attempting to save data from an Excel Sheet to an Access Table. The number one problem is I'm not an administrator on my system. When I attempt to set the references to the data objects in references I get the message that I'm unable to access the system registery.
    My question is there way to add those references that will work on all systems.
    If there isn't a way to add those references. Help !!.
    This code works until "AddNew" and I receive a run-time error 3251.
    Code: (Note: This code works on a system admin rights)

    Sub test()
    '   Database information
    DBFullName = Sheet6.Range("T2")
    '   Open the connection
        Set Connection = CreateObject("adodb.Connection")
        Cnct = "Provider=Microsoft.Jet.OLEDB.4.0; "
        Cnct = Cnct & "Data Source=" & DBFullName & ";"
        Connection.Open ConnectionString:=Cnct
    '   Create RecordSet
        Set Recordset = CreateObject("adodb.Recordset")
    '   Next two lines critical to work in QPro properly.  Excel does not need them.
        Recordset.CursorType = adOpenKeyset
    With Recordset
    '       Filter
            Src = "SELECT * FROM VisitData"
            'Src = Src & "and CategoryID = 30"
            .Open Source:=Src, ActiveConnection:=Connection
    '   Cells.Clear 'Used in Excel to clear a sheet
    '       Write the field names
            'For Col = 0 To .Fields.Count - 1
               'Range("A1").Offset(0, Col).Value = Recordset.Fields(Col).Name   'Excel method
            'Next
    .AddNew
         Recordset(Sheet6.Range("D2")) = Sheet1.Range(Sheet6.Range("B2"))
        Recordset(Sheet6.Range("D3")) = Sheet1.Range(Sheet6.Range("B3"))
        Recordset(Sheet6.Range("D5")) = Sheet1.Range(Sheet6.Range("B5"))
        .Update
    End With
    Set Recordset = Nothing
        Connection.Close
        Set Connection = Nothing
    End Sub
    Last edited by Aussiebear; 03-24-2019 at 01:56 AM. Reason: Added tags to suit code submitted

Posting Permissions

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