Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to query a MS-Access Table from MS-Excel (2010) using VBA
- strFile = "C:UsersbwallDesktopExcel Query Access Testing"
- Dim cn As Object
- Dim rs As Object
- Dim strSql As String
- Dim strConnection As String
- Dim AppPath As String
- Set cn = CreateObject("ADODB.Connection")
- AppPath = Application.ActiveWorkbook.Path
- strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
- "Data Source=" & AppPath & "Masterlist_Current_copy.accdb;"
- Debug.Print strConnection
- strSql = "SELECT [Neptune Number],[Description],[Manufacturer],[Manufacturer P/N] FROM [All Components];"
- cn.Open strConnection
- Set rs = cn.Execute(strSql)
- MsgBox rs.Fields(0) & " rows in MyTable"
- rs.Close
- Set rs = Nothing
- cn.Close
- Set cn = Nothing
- End Sub
- Dim conn As Object
- Set conn = CreateObject("ADODB.Connection")
- Public Sub foo()
- Dim cn As Object
- Dim rs As Object
- Dim strSql As String
- Dim strConnection As String
- Set cn = CreateObject("ADODB.Connection")
- strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
- "Data Source=C:Accesswebforumswhiteboard2003.mdb"
- strSql = "SELECT Count(*) FROM MyTable;"
- cn.Open strConnection
- Set rs = cn.Execute(strSql)
- MsgBox rs.fields(0) & " rows in MyTable"
- rs.Close
- Set rs = Nothing
- cn.Close
- Set cn = Nothing
- End Sub
Add Comment
Please, Sign In to add comment