Access To Excel and Back to Access

ColinKJ

Well-known Member
Joined
Jan 27, 2009
Messages
983
Hi All,

Can anyone help me with some example code that extracts data from an Acces table, then when changed in Excel, an example of code to write the data from Excel back to Access.

Any assistance would be much appriciated.

Cross-post link: http://www.mrexcel.com/forum/showthread.php?t=566755
 
Last edited by a moderator:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I developed this subroutine for getting data from an access mdb file

strSrc = the path and filename of the datasource
strSql = the sql query
rng = the top left cell where you want the data dumping.

As for passing data back to Access, I've not had do to that as yet...

HTH

Code:
Sub getReadSQL(ByVal strSrc As String, strSql As String, rng As Range)
    Application.DisplayAlerts = False
    With ActiveSheet.QueryTables.Add(Connection:= _
        "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;" & _
        "Data Source=" & strSrc & ";Mode=Share Deny write;" & _
        "Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";" & _
        "Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;" & _
        "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;" & _
        "Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;" & _
        "Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;" & _
        "Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" _
        , Destination:=rng)
        .CommandType = xlCmdTable
        .CommandText = strSql
        .name = "getReads"
        .FieldNames = False
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertEntireRows
        .SavePassword = True
        .saveData = False
        .AdjustColumnWidth = False
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceDataFile = strSrc
        .Refresh BackgroundQuery:=False
        .Delete
    End With
    Application.DisplayAlerts = True
End Sub
 
Upvote 0
Hi Weaver,

Many thanks for your example code.

I'm ok with VBA code for Excel, but not yet for Access queries from Excel.

I'll work my way through the example and se if I can work out what is happening.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,282
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top