Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default command button to run an Acess query- I know this can be done

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

"chris23892 via OfficeKB.com" wrote:

Hi all! Here's a new twist:

I want to create a command button in Excel that will run a query in my
database.

Here's why:

Our data base is not that locked down, I don't want everyone poking around in
this. What I've done is create a query to run the data output that people
want. I already have a command button in my form in our data base to run this,

export it to a nice neat spreadsheet.

What I need is to create a tab in this spreadsheet with a command button that
will run this query in my database so people don'r poke around in the actual
data base.

I'm having issues pointing Excel to the query in VBA. I know this can be done.


Any thoughts?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200808/1


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default command button to run an Acess query- I know this can be done

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wanting to Create A Command Button Command bumper338 Excel Programming 3 May 7th 07 06:53 PM
why does edit query button not open query needlemaker Excel Discussion (Misc queries) 0 June 29th 06 03:18 PM
VB's Command Button vs Form's Command Button Ronald Dodge Excel Programming 3 May 24th 06 02:23 PM
MS Query, command View-Query Properties Frans van Zelm Excel Discussion (Misc queries) 0 January 6th 05 02:24 PM
Command button macro query BeSmart[_2_] Excel Programming 5 April 15th 04 01:27 PM


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"