LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Evaluate text formula in VBA

Please someone help me with Evaluate function. I have some rules written in
Access table as string with predefined variables in it like:

and(" & CCA & "<30, " & CCB & "800)
and(""" & AAA & """=""" & AAB & """, """ & BBA & """<""" & BBB & """)
and(" & CCA & "<24, """ & BBA & """=""8o6t56565a"")

Then I'm trying to get these rules, supply with the same variables, Evaluate
them in excel and get True or False results. The code lookes like:

Sub HitRules()
Dim k As Integer
Dim DBS As New ADODB.Connection
Dim rstAl As New ADODB.Recordset
Dim AAA, AAB, BBA, BBB As String
Dim CCA, CCB As Long
Dim hhhh

With DBS
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0"
.Open "D:\TestDB.mdb"
End With
rstAl.Open "Select * from Rules", DBS, adOpenStatic, adLockReadOnly
AAA = "0503"
AAB = "0503"
BBA = "8o6t56-a"
BBB = "8o6t56-b"
CCA = 22
CCB = 1200
For k = 0 To rstAl.RecordCount - 1
hhhh = CStr(rstAl!Rule) 'formulas provided above are stored in
rstAl!Rule
Debug.Print k+1 & " - " & Evaluate(hhhh) 'Result should be True or
False
rstAl.MoveNext
Next k
rstAl.Close
DBS.Close
End Sub

But it does not work... It seems that Evaluate does not understands variable
names (AAA, AAB, etc.) and the result is always False(?). And on the 3'rd
rule, error msg appeares: runtime error 13 - type mismatch...
Please advice me something how to avoid this problem. Is there any other way
to read and execut the string formulas?
 
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
Evaluate text strings as a formula Nick Flyger Excel Programming 5 October 4th 06 11:08 AM
Using OR to evaluate TEXT stacy[_2_] Excel Programming 2 August 26th 05 08:10 PM
converting constant/text to formula and evaluate it tsuoying Excel Programming 1 February 19th 05 04:28 PM
VBA Function to evaluate hlookup text string as formula Eric[_22_] Excel Programming 2 August 2nd 04 04:57 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 01:56 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"