Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 349
Default Evaluate Custom Expression

Dears,

I'd like to create a TextBox and allow users to enter an expression, for
instance,
CompanyName = 'ABC' AND DeptName = '" & C1 & "' AND EmployeeName = '" &
NamedRange1 & "'"

This is a where clause like expression and I'd like to get the cell
reference / name range reference in my code. Is there any method that I can
use to evaluate an expression and obtain the actual values and then concat to
my SQL string? Or I have to use InStr or other indirect methods to create an
expression?

Thanks a lot!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Evaluate Custom Expression

Dim s as String

s = "CompanyName = 'ABC' AND DeptName = '" & Range("C1").Value _
& "' AND EmployeeName = '" & Range("NamedRange1").Value & "'"

--
Regards,
Tom Ogilvy

"Peter" wrote in message
...
Dears,

I'd like to create a TextBox and allow users to enter an expression, for
instance,
CompanyName = 'ABC' AND DeptName = '" & C1 & "' AND EmployeeName = '" &
NamedRange1 & "'"

This is a where clause like expression and I'd like to get the cell
reference / name range reference in my code. Is there any method that I

can
use to evaluate an expression and obtain the actual values and then concat

to
my SQL string? Or I have to use InStr or other indirect methods to create

an
expression?

Thanks a lot!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 349
Default Evaluate Custom Expression

Thanks Tom, and is there any other automated way to do so?

Base on your solution, I still have to parse the string (from a TextBox),
locate " & __ & " characters and then change it to "Range()" property
manually.

Thanks,

"Tom Ogilvy" wrote:

Dim s as String

s = "CompanyName = 'ABC' AND DeptName = '" & Range("C1").Value _
& "' AND EmployeeName = '" & Range("NamedRange1").Value & "'"

--
Regards,
Tom Ogilvy

"Peter" wrote in message
...
Dears,

I'd like to create a TextBox and allow users to enter an expression, for
instance,
CompanyName = 'ABC' AND DeptName = '" & C1 & "' AND EmployeeName = '" &
NamedRange1 & "'"

This is a where clause like expression and I'd like to get the cell
reference / name range reference in my code. Is there any method that I

can
use to evaluate an expression and obtain the actual values and then concat

to
my SQL string? Or I have to use InStr or other indirect methods to create

an
expression?

Thanks a lot!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Evaluate Custom Expression

The solution Tom gave you would create a string variable which could be
plugged straight into your SQL. Why would you need to parse that?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Peter" wrote in message
...
Thanks Tom, and is there any other automated way to do so?

Base on your solution, I still have to parse the string (from a TextBox),
locate " & __ & " characters and then change it to "Range()" property
manually.

Thanks,

"Tom Ogilvy" wrote:

Dim s as String

s = "CompanyName = 'ABC' AND DeptName = '" & Range("C1").Value _
& "' AND EmployeeName = '" & Range("NamedRange1").Value & "'"

--
Regards,
Tom Ogilvy

"Peter" wrote in message
...
Dears,

I'd like to create a TextBox and allow users to enter an expression,

for
instance,
CompanyName = 'ABC' AND DeptName = '" & C1 & "' AND EmployeeName = '"

&
NamedRange1 & "'"

This is a where clause like expression and I'd like to get the cell
reference / name range reference in my code. Is there any method that

I
can
use to evaluate an expression and obtain the actual values and then

concat
to
my SQL string? Or I have to use InStr or other indirect methods to

create
an
expression?

Thanks a lot!






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 349
Default Evaluate Custom Expression

It is because user won't enter a string like:
MyName = '" & Range("Name1") & "' AND ....

but they'd enter : MyName = 'ABC' AND AnotherName = '" & Name1 & "'"...

So I still have to parse the input and transform to a proper format, or am I
think in the wrong way?

THanks

"Bob Phillips" wrote:

The solution Tom gave you would create a string variable which could be
plugged straight into your SQL. Why would you need to parse that?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Peter" wrote in message
...
Thanks Tom, and is there any other automated way to do so?

Base on your solution, I still have to parse the string (from a TextBox),
locate " & __ & " characters and then change it to "Range()" property
manually.

Thanks,

"Tom Ogilvy" wrote:

Dim s as String

s = "CompanyName = 'ABC' AND DeptName = '" & Range("C1").Value _
& "' AND EmployeeName = '" & Range("NamedRange1").Value & "'"

--
Regards,
Tom Ogilvy

"Peter" wrote in message
...
Dears,

I'd like to create a TextBox and allow users to enter an expression,

for
instance,
CompanyName = 'ABC' AND DeptName = '" & C1 & "' AND EmployeeName = '"

&
NamedRange1 & "'"

This is a where clause like expression and I'd like to get the cell
reference / name range reference in my code. Is there any method that

I
can
use to evaluate an expression and obtain the actual values and then

concat
to
my SQL string? Or I have to use InStr or other indirect methods to

create
an
expression?

Thanks a lot!








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Evaluate Custom Expression

I would have thought that if they are inputting the complex string that you
quote, and that they understand Names and are entering those, then getting
them to also add Range("...") would not be a problem.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Peter" wrote in message
...
It is because user won't enter a string like:
MyName = '" & Range("Name1") & "' AND ....

but they'd enter : MyName = 'ABC' AND AnotherName = '" & Name1 & "'"...

So I still have to parse the input and transform to a proper format, or am

I
think in the wrong way?

THanks

"Bob Phillips" wrote:

The solution Tom gave you would create a string variable which could be
plugged straight into your SQL. Why would you need to parse that?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Peter" wrote in message
...
Thanks Tom, and is there any other automated way to do so?

Base on your solution, I still have to parse the string (from a

TextBox),
locate " & __ & " characters and then change it to "Range()" property
manually.

Thanks,

"Tom Ogilvy" wrote:

Dim s as String

s = "CompanyName = 'ABC' AND DeptName = '" & Range("C1").Value _
& "' AND EmployeeName = '" & Range("NamedRange1").Value & "'"

--
Regards,
Tom Ogilvy

"Peter" wrote in message
...
Dears,

I'd like to create a TextBox and allow users to enter an

expression,
for
instance,
CompanyName = 'ABC' AND DeptName = '" & C1 & "' AND EmployeeName =

'"
&
NamedRange1 & "'"

This is a where clause like expression and I'd like to get the

cell
reference / name range reference in my code. Is there any method

that
I
can
use to evaluate an expression and obtain the actual values and

then
concat
to
my SQL string? Or I have to use InStr or other indirect methods to

create
an
expression?

Thanks a lot!








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 349
Default Evaluate Custom Expression

It is because user won't enter a string like:
MyName = '" & Range("Name1") & "' AND ....

but they'd enter : MyName = 'ABC' AND AnotherName = '" & Name1 & "'"...

So I still have to parse the input and transform to a proper format, or am I
think in the wrong way?

THanks
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Evaluate Custom Expression

If they enter it that way and Name1 is meant to refer to a defined name on
the worksheet, then I think you would have to parse it out and resolve it.

--
Regards,
Tom Ogilvy


"Peter" wrote:

It is because user won't enter a string like:
MyName = '" & Range("Name1") & "' AND ....

but they'd enter : MyName = 'ABC' AND AnotherName = '" & Name1 & "'"...

So I still have to parse the input and transform to a proper format, or am I
think in the wrong way?

THanks

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
Structured references in custom Data Validation expression? kr/nk Excel Discussion (Misc queries) 11 February 2nd 10 06:28 PM
evaluate a concatenate expression Russell.Ivory[_2_] Excel Worksheet Functions 3 November 4th 09 05:52 PM
value expression RayB Excel Worksheet Functions 7 January 17th 07 09:57 PM
need help with expression Peterpunkin Excel Discussion (Misc queries) 5 May 4th 06 05:56 PM
How to evaluate a text expression as formula ? Krzysztof Klimczak Excel Programming 0 August 29th 03 04:31 PM


All times are GMT +1. The time now is 09:41 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"