Passing a textbox control to an eval function

K

KubixKiller

Hello,

I'm trying to pass a textbox to an eval function. For example:

function TestLog(message as string, optional txtLog as variant) as
boolean
dim fCall as string
fCall = "TestFunction(" + txtLog + ")"
debug.print eval (fcall)

end function

I want to call a lot of functions that are present in a table. One of
the parameters is a textbox where certain logging is done. However: I
get error whatever I try. I think I should pass the address of the
textbox, but I don't know how.

I already tried:

fCall = "TestFunction(txtLog)"

but that doesn't work either.

Suggestions anyone?
 
D

Douglas J Steele

It would have helped to mention what error you're getting. I'm assuming it's
complaining about data type mismatches. If so, that's because the value
you're passing needs to be in quotes:

fCall = "TestFunction(" & Chr$(34) & txtLog & Chr$(34) & ")"

Chr$(34) is the same as ". If you'd prefer not using that function, you'd
need

fCall = "TestFunction(""" & txtLog & """)"

Note that I'm using & for concatenation, not +. & is preferred when dealing
with text.

Remember, too, that txtLog is an optional parameter. If you don't supply a
value for it, the code won't work.

To handle that, you'd need:

dim fCall as string

If IsMissing(txtLog) = False Then
fCall = "TestFunction(" & Chr$(34) & txtLog & Chr$(34) & ")"
debug.print eval (fcall)
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top