Running VBA code within a Macro

J

J

I have a macro that is supposed to run VBA code that contains a
function. This function contains code that decides which of 2 queries
to run depending on if a check box is checked or not. In my macro i
have the "RunCode" option selected and "chkMisc()" selected as the
Function name. I get an error when I click my update button that says
"The expression you entered has a function name that STATUS can't find"

Here's the function that I'm using:

Public Function chkMisc()
If Me.chk1.value = True Then
DoCmd.OpenQuery "Status wk 01 Jobs Not in Job Card Table"
End If

If Me.chk1.value = False Then
DoCmd.OpenQuery "Status wk 01 Serial Numbers not in Job Card Table"
End If
End Function

Let me know if I left out any piece of information that might be needed
to solve this problem. Any help is appreciated.
 
K

Ken Snell \(MVP\)

Is your function in a regular module? Is the module named differently from
the function (they cannot have the same name)?
 
J

Jeff Boyce

Why are you referring to

Me.chk1.Value

If this is a function, and you are running it in a macro, what does the
"Me." refer to?
 
J

J

The function is in the code located in a "Status wk 01" form. The "Me"
is supposed to be referring to the text box. The function was coded in
the VBA code window and is not loaded as a module. Could my problem be
that I used "Me" as opposed to something else that would be needed in
it's place? If so, what would the correct syntax be for correcting
this problem?
 
K

Ken Snell \(MVP\)

You cannot run a function from a macro if that function is located in a
form.

If the code is in the form, why not use an event related to the form or one
of its controls to run the function? Then you don't need a macro at all.

Tell us more about just exactly what you're trying to do.
 

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