If Than elseif this is to difficult

Mathematician

Registered User.
Local time
Today, 10:40
Joined
Nov 23, 2007
Messages
17
Hi all,

I would like to create the following code:

------------------------------------
sub test()

condition= "4=4 and 5=5 and 6=6"
result="msgbox("It is ok")"

if condition then result
end if


end sub

------------------------------------

or

sub test2()

sentence="if 4=4 then msgbox("im the boss")"
sentence

end sub

------------------------------------

Do you have any idea how to make the two above work? The code doesn't recognize "=" and "and" words from the condition string it is not treated as if structure.

I wanted to do so because I have table and in one column I have in each row the all sequence for example (if 4=4 then msgbox("im the boss")).
So I wanted to use:
if currentdb().openrecordset("Table")![Condition] then currentdb().openrecordset("Table")![Result]

Many thanks in advance for any clue

Mathematician
 
I assumed that you were actually enclosing the logical test within the quotes... which is certain to fail given all else.

This will work:

Public Sub test()
Dim condition As Boolean
Dim msg As String

condition = 4 = 4 And 5 = 5 And 6 = 6
If condition Then msg = "it is ok"

MsgBox msg

End Sub
 
Math,

Not sure what you're trying to do here.

condition = "4 = 4 And 5 = 5 And 6 = 6"

If Eval(condition) Then MsgBox("it is ok")

Wayne
 
Thank You all,

The two solutions above are grat. But i am trygin to implement it into the code and I cannot handle with it.
Do you know how to make him to run the code like:
sub test2()

if eval([Tables]![Table Name]![Column Name]) then
eval([Tables]![Table Name]![Column Name])
end sub
Because this one below doesn't work :(

Maybe You could help how to do this one:

sub test()

set db1=currentdb().openrecordset("Table1")
set db2=currentdb().openrecordset("Table2")

condition = "db1![Column1]"
result="db1![Column2]"

if Eval("db2!" & condition) then
eval("db2!" & result)
end if

end sub

In db1![Column1] you will find for example "[Column12]='Yes' "
and
in db1![Column2] you will find for example "[Column13]='Yes is present' "

It gives me the message that he doesn't understand db2. It looks that he would like to read my code as something like
eval(Tables![Table Name]![Column Name]) buthe doesn't understand db1 and db2 as
set db1=currentdb().openrecordset("Table1")
set db2=currentdb().openrecordset("Table2")
:(

Thank You for any advice.

Mathematician
 
Math,

You're gonna have to make this a little clearer ... what are you trying to do?

W
 
So,

I have table Cond and it has two columns: Condition, Result.
And I have another table Final and here have Three columns: Name, Last Name, Age
For example in thirst row in table Cond I have strings:
Condition = "[Final].[Name]=Wayne and [Final].[Age]=123"
Result="[Final].[Last Name]=Ryan"

And I would like to implenet the following code:

if Condition then Result

So the programm will check what is in: [Final].[Name] and [Final].[Age] and based on it he will update the [Final].[Last Name]
That's all what I wanted to do :)

But the conditions must be given in [Cond] table.

Thank U for Your time.

Mathematician
 
Do the fields in the Cond table have the field names of the Final table in them? If they didn't you could have concatenated the fields from final and joined the concatenated to the cond table and got the result , or maybe used a DLOOKUP.

Brian
 
Are you trying to TEST for missing data?
For example, a missing LAST name or a missing BIRTHDAY.
 
Math,

Code:
Dim rst As DAO.Recordset
Dim strResult As String

Set rst = CurrentDb.OpenRecordset("Select * From Condition")

While Not rst.EOF And Not rst.BOF
   If DCount("[Result]", "Final", rst!Condition) > 0 Then
      DoCmd.RunSQL "Update Final " & _
                   "Set " & rst!Result & " " & _
                   "Where " & rst!Condition & ";"
   End If
   rst.MoveNext
   Wend

Actually, you don't even need the If DCount ... because the Where clause will only apply the update if the
Condition is satisfied.

Wayne
 
Last edited:
Thank You all,

SQL is the best solution in my situation. It works very well now.
It is, what I was looking for.

Thanks again,

Mathematician
 

Users who are viewing this thread

Back
Top Bottom