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!

Run code from Runmacro in Macro

Status
Not open for further replies.

micang

Technical User
Aug 9, 2006
626
US
Access 2003

Hi All,

I have the following code in a module:

Code:
Function TableExist(Name As String) As Boolean
     
    Dim objTable As TableDef
     
    On Error Resume Next
    Set objTable = CurrentDb.TableDefs(Name)
    TableExist = Not objTable Is Nothing
     
    Exit Function
     
End Function
 
Sub Test()
     
    Dim strName As String
     
    strName = "Customers"
    If TableExist(strName) Then
        MsgBox "Table " & strName & " Exists", vbInformation
    Else
        MsgBox "Table " & strName & " Does Not Exist", vbExclamation
    End If
     
End Sub

I would like to run it from a macro (RunCode).

I have tried, but I keep getting errors e.g. "The expression you entered has a function name that Microsoft Office can't find."

Am a novice, thanks for all the help.

Michael
 
Place "Public" in front of the function name so it can be seen anywhere in the database,
Code:
[COLOR=red]Public[/color] Function TableExist(Name As String) As Boolean


 
Hi, I tried that, but I still get the error?

In Macro\RunCode\Function Name I put in "TableExist()"

but I still get the error?

Am I still doing something wrong?

Many thanks

Michael
 
Why do you need a macro (instead of VBA) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

Macros' RunCode action, expects a Function and not a Sub. So if you change the Sub Test() to Function Test() you 'll be ok.

But PHV suggestion should be seriously concindered ( and I think that's why he didn't provide the answer....!)
 
Thanks Jerryklmns. Did not know that.

PHV and JerryKlmns you are both correct. I am new to access/vba and I have been running "procedures" via macros, but I am begining to see how limited one is.

So I am slowly trying to learn VBA.

Thanks again.

Michael
 

On menu Tools-->Macro --> Convert Macros to Visual Basic

would be usefull for you to start with...
 
and I think that's why he didn't provide the answer
Well spotted !
I'm reluctant to give macros answers, especially in a VBA forum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top