Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use code stored in a table in vba

Status
Not open for further replies.

mbiro

Programmer
Nov 20, 2001
304
I am wondering how to store several if...then statements in a table and then call the statement in my vba code (calling the appropriate if..then from aparameter passed)?

Thinking...

a table-

id stmnt
1 if x=1 then...
2 if x=1 then...
3 if x=1 then...

vba -

Public Function artofunction(an8 As Long, cend As Integer)
Dim dbs As Database
Dim rst As Recordset
Dim x As Variant

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT tblcase.fmemo FROM tblaccounts RIGHT JOIN (tblcase RIGHT JOIN tblcasedtl ON tblcase.flngcase = tblcasedtl.flngcase) ON tblaccounts.flngan8 = tblcasedtl.flngan8 where tblcasedtl.flngan8 = " & an8, dbOpenDynaset)
While Not rst.EOF
x = rst!fmemo
rst.MoveNext
Wend

USING THE VALUE X TO USE THE IF...THEN STATEMENT RETURNED


End Function

Is this possible?
 
You can probably accomplish what you need with a CASE statement instead of putting the if statements in a table.

Basic Structure is.
int1 = 2
Select Case int1
Case 1
Debug.Print "1"
Case 2
Debug.Print "2"
Case 3
Debug.Print "3"
Case Else
Debug.Print "None"
End Select
 
To some extent you could use the "Eval" functoin. It is in "Help"

e.g.

MyF = "2 + 3 ^ 3"

? eval(MyF)
29

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top