Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel open an existing MS Query in edit mode via macro attached to a button.

I have an Excel spreadsheet with an MS Query on it. The end user
wants to click on a button that will run an attached macro in VBA that
opens the query it edit mode so he can change the date range in the
criteria. The macro does some other work also. I cannot use
parameters or values in cells on the spreadsheet because of a
disagreement in the date/time formatting between Excel and the ODBC
database the query uses. I searched the google groups for a half hour
and tried the VBA & Excel help files but could not find it.

Thanks for any help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Excel open an existing MS Query in edit mode via macro attached to a button.

How about modifying the WHERE clause of the query string of the QueryTable
directly. I assume you can get the desired date information from the user
via an InputBox or a UserForm and then use that information to build a new
query string. See the code below, which is an example using QueryTables (MS
Query) with an external Excel file.

Troy


Sub Test1()

Dim sSQL As String
Dim sWhere As String

'''Display the current query string.
MsgBox Sheet1.QueryTables(1).Sql

'''This is the static portion of the query string that doesn't change.
'''(Example: Query a named range: nData in an Excel file:
DataSource1.xls).
sSQL = "SELECT * FROM `C:\My Documents\DataSource1`.nData nData"

'''Define the new query string (put a space between the 2 strings).
sWhere = "WHERE (nData.myCol1 1.2)" '''<===== Modify this string
sSQL = sSQL & " " & sWhere

'''Set the Query Table Sql property to the new query string.
Worksheets(1).QueryTables(1).Sql = sSQL

'''Display the new query string.
MsgBox Sheet1.QueryTables(1).Sql

'''Refresh the Query Table data on the worksheet.
Worksheets(1).QueryTables(1).Refresh

End Sub


"systems analyst" wrote in message
om...
I have an Excel spreadsheet with an MS Query on it. The end user
wants to click on a button that will run an attached macro in VBA that
opens the query it edit mode so he can change the date range in the
criteria. The macro does some other work also. I cannot use
parameters or values in cells on the spreadsheet because of a
disagreement in the date/time formatting between Excel and the ODBC
database the query uses. I searched the google groups for a half hour
and tried the VBA & Excel help files but could not find it.

Thanks for any help!



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
macro attached to command button - VBA form Roy Gudgeon[_2_] Excel Discussion (Misc queries) 2 March 16th 10 12:44 PM
How can I edit my macro button images in Excel 2007. Tarbe Excel Discussion (Misc queries) 3 April 13th 07 03:22 PM
I know you can't run a macro while in edit mode, but... [email protected] Excel Discussion (Misc queries) 5 July 21st 06 03:40 AM
why does edit query button not open query needlemaker Excel Discussion (Misc queries) 0 June 29th 06 03:18 PM
running macro while in the edit mode Bob[_23_] Excel Programming 2 July 24th 03 01:38 AM


All times are GMT +1. The time now is 11:08 PM.

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

About Us

"It's about Microsoft Excel"