I got to thinking....I have buttons in acess that have code behind them to
run what I need. I guess I'm wanting to run this code from my excel sheet.
Here's an example:
Private Sub Command18_Click()
Dim sXL As String, oXL As Object
sXL = "\Full Database.xls" 'Full path to my spreadsheet
' Insert the actual name of your query between the quotes below
DoCmd.TransferSpreadsheet acExport, , "Master Export query", sXL
Set oXL = CreateObject("Excel.Application")
oXL.Visible = True
oXL.WorkBooks.Open FileName:=sXL
End Sub
This code is assigned to a command buttom in my data base. Works like a charm.
(note this code is in the MS access database)
How would I run this from a command button in a excel spreadsheet?
dmoney wrote:
This should get you started -- just adjust the code to meet your dbase and
assign to a button -- you will need to make sure the microsoft activex data
objects 2.7 reference is selected in the excel vb editor under
tools..references as well.
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strsql As String
'MAIN PROC
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.Open "\\xxx\xxx\xxx\yyy.mdb", "admin", ""
cn.CursorLocation = adUseClient
strsql = "SELECT [xxx].[xx], [xx].[RxxxEQ_], [yyy].[yyyy] " _
& "FROM [sdfsdf];"
rs.Open strsql, cn
Sheets("xxx").Select
rs.MoveFirst
Do Until rs.EOF = True
ActiveCell = rs![xxx]
ActiveCell.Offset(0, 1) = rs![xxxx]
ActiveCell.Offset(0, 2) = rs![xxxxx]
ActiveCell.Offset(0, 3) = rs![xxxxxxx]
ActiveCell.Offset(1, 0).Activate
rs.MoveNext
Loop
rs.Close
Hi all! Here's a new twist:
[quoted text clipped - 16 lines]
Any thoughts?
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200808/1