Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Excel and MS Query

Is it possible to set the value of the 'value' criteria with MSQuery using
data entered into a UserForm in Excel?

What i would like to do is to have a variable for the Like value in MS query
and the value of this variable is set in a UserForm in excel.

I have a macro which displays a UserForm into which i would like the enter
the criteria. The macro then runs the desired MS Query but i am unable to
refine the query using the information entered in to the Textbox. When i use
this variable to define the 'Where' part of the 'Select' 'From' 'Where'
function the Query errors.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Excel and MS Query

You might try something like this.

Private Sub CommandButton1_Click()
If Len(Trim(TextBox1)) 0 And Not IsNull(TextBox1) Then
Set qt = Worksheets(1).QueryTables(1)
With qt
.CommandType = xlCmdSql
.CommandText = _
"SELECT ContactID, NameStyle, Title, " _
& "FirstName, MiddleName, LastName, " _
& "Suffix, EmailAddress, EmailPromotion, " _
& "Phone, PasswordHash, PasswordSalt, " _
& "AdditionalContactInfo, rowguid, ModifiedDate " _
& "FROM AdventureWorks.Person.Contact Contact " _
& "WHERE (LastName Like '" & Trim(TextBox1) & "%') "
.Refresh
End With
End If
Unload Me
End Sub

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Confused Slug" wrote:
| Is it possible to set the value of the 'value' criteria with MSQuery using
| data entered into a UserForm in Excel?
|
| What i would like to do is to have a variable for the Like value in MS
query
| and the value of this variable is set in a UserForm in excel.
|
| I have a macro which displays a UserForm into which i would like the enter
| the criteria. The macro then runs the desired MS Query but i am unable to
| refine the query using the information entered in to the Textbox. When i
use
| this variable to define the 'Where' part of the 'Select' 'From' 'Where'
| function the Query errors.


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
Excel 2007 / MS Query - editing existing query to another sheet Hotpepperz Excel Discussion (Misc queries) 0 June 13th 08 06:53 PM
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? jocke Excel Discussion (Misc queries) 1 November 29th 05 01:44 PM
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? jocke Excel Discussion (Misc queries) 0 November 28th 05 06:37 PM
Edit Query from Excel will not open query in MSQuery Michelle Excel Programming 0 February 21st 05 03:59 PM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM


All times are GMT +1. The time now is 04:38 AM.

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"