Hi Paul,

1: Public Sub OpenDb(strSql As String)

    Dim cnn                 As New ADODB.Connection
    Dim rstData             As New ADODB.Recordset
    Dim strDbConnectStr     As String
    Dim strDbPath           As String
    
    strDbPath =* ThisWorkbook.Path & "\**Your Accessbase name**"  *
    strDbConnectStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & *
strDbPath*
    With cnn
        .Open strDbConnectStr
        .Execute strSql
        .Close
        'On Error GoTo 0
    End With
    
    Set cnn = Nothing
    Set rstData = Nothing
    strSql = vbNullString
    strDbConnectStr = vbNullString
    Exit Sub
End Sub

Above Procedure Can be used to query on a table in to Access database As 
you can see *Strsql has *passed as perimeter this is your query that you 
want to excute.

for exmaple 

sub Test()
dim strs  as string 

strs="delete * from table1"
OpenDb(strs)

end sub

but befor doing this you need to add a reference [microsoft activex object 
2.0] in VBA from tool->reference

2: this example is getting data in recordset and pasting the same on excel 
sheet: 

Public Sub GetDataOnSheet(strSql As String)
       
    Dim cnn                 As New ADODB.Connection
    Dim rstData             As New ADODB.Recordset
    Dim strDbConnectStr     As String
    Dim strDbPath           As String
    Dim intHeader           As Integer

    strDbPath = ThisWorkbook.Path & "\*Your Accessbase name *"
    strDbConnectStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & 
strDbPath
    
    On Error GoTo ErrHandle
    cnn.Open strDbConnectStr
    On Error GoTo 0
    
    With rstData
        .CursorType = adOpenStatic
        .CursorLocation = adUseServer
        .LockType = adLockOptimistic
        .ActiveConnection = cnn
        .Open strSql
         ThisWorkbook.Worksheets("Sheet1").Range("A1").CopyFromRecordset 
rstData
        .Close
    End With
    cnn.Close
    Set cnn = Nothing
    Set rstData = Nothing
    strSql = vbNullString
    strDbConnectStr = vbNullString
    Exit Sub
    
ErrHandle:
    MsgBox "Check if the Database and Table is existing or not in the 
Path---" & Chr(10) & " " & strDbPath
End Sub


your access Data base name Could like this: db1.mdb


Regards
Prince





On Monday, March 4, 2013 11:50:41 PM UTC+5:30, Paul Schreiner wrote:
>
> I may regret asking this, but here goes:
>  
> Using Office 2010:
>  
> I have Excel templates that are used to create documents and store the 
> data in an Oracle database.
> The Oracle database has data from "released" and "archived" or 
> "historical" documents.
>  
> These documents are saved as PDF's and stored on a Sharepoint site.
>  
> I use Excel to generate multiple reports from various data sources (mostly 
> Oracle databases).
>  
> I'd like to use Excel VBA to retrieve a list of "released" documents from 
> a specific table in Sharepoint.
>  
> I'll then retrieve the Oracle data for the Release documents.
>  
> Now, I've been told that I can link an Access table to the Sharepoint 
> table, then use Excel VBA to query the Access table.
>  
> I have successfully created an Access Database that is linked to the 
> Sharepoint site.
>  
> I've Googled my fingers off and read hundreds of lines in posts and have 
> yet to find a WORKING example of using Excel VBA to query the AccessDB.
>  
> (no, I DON'T want to use Excel and create an external data source, I'd 
> like to use VBA and issue an SQL query against the database)
>  
> It seems more efficient to connect to the Sharepoint table directly from 
> Excel VBA instead of going through MSAccess.
>  
> So.. my question:
> Does anyone have a working example of connecting to, and querying an 
> Access Database using Excel VBA?
>  
> Or...
> Does anyone have a working example of connecting to and querying a 
> Sharepoint site/table using Excel VBA?
>  
> thank you,
> Paul
>  
>

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to