Showing posts with label Access. Show all posts
Showing posts with label Access. Show all posts

Saturday, June 3, 2017

Switching focus from Excel to an Access DB Window

Try this, you'll have to modify to suit. when you want to switch from excel to access, add
appactivate "Microsoft Access"

Private Declare Function showwindow Lib "user32" (ByVal hwnd As Long, ByVal ncmdshow As Long) As Long Private Const sw_shownormal = 4 Private Sub OpenDatabase_Click() Dim results Dim objAccess As Object Dim i As Integer Dim whwnd As Long On Error Resume Next Set objAccess = GetObject(, "access.application") If objAccess Is Nothing Then 'get a reference to the access application object Set objAccess = GetObject("", "access.application") 'open the database objAccess.opencurrentdatabase "C:\GMD\GMD Simulation.mdb" whwnd = Findwindow("Microsoft Excel", vbNullString) showwindow whwnd, sw_shownormal If whwnd = 0 Then AppActivate "GMD Simulation Input" End If End If Set objAccess = Nothing End Sub

Excel VBA Connection to Access

read some of this tutorial on ADO. You don't have to read everything. Focus on the connection object and recordset object (see section called "Getting data")

One way to use Access is not only to store the data in it, but also the queries that you require (can be parameter queries).  article here on how to create the queries from Excel. Now you don't have to create them from Excel but the code does show how to create the connection. And what may be of further use is the part that describes how to run queries in Access.

Finally, the most common way of dumping data from an ADO recordset to a range is by using the CopyFromRecordset method, so have a look at that.