ckmi1
03-22-2019, 02:07 PM
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
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