Trying to make a query ask for input

R

rjohannes

I have been referencing a help topic of the name 'make a query ask for input'
but I am having a hard time with the VBA code. (I admit I don't know much at
all about the code) The help topic had me copy and paste a section of code
into a module, the code looks like this:

Function IsLoaded (ByVal strFormName As String) As Boolean

Dim oAccessObject As AccessObject
Set oAccessObject = CurrentProject.AllForms(strFormName)

If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign Then
IsLoaded = True
End If
End If

When I run the macro this error message pops up:

Compile error:
Expected End Function

With the last 'End If' highlighted, when I click okay it highlights in
yellow the very first line starting the function.

Am I doing something wrong?
 
M

Marshall Barton

rjohannes said:
I have been referencing a help topic of the name 'make a query ask for input'
but I am having a hard time with the VBA code. (I admit I don't know much at
all about the code) The help topic had me copy and paste a section of code
into a module, the code looks like this:

Function IsLoaded (ByVal strFormName As String) As Boolean

Dim oAccessObject As AccessObject
Set oAccessObject = CurrentProject.AllForms(strFormName)

If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign Then
IsLoaded = True
End If
End If

When I run the macro this error message pops up:

Compile error:
Expected End Function

With the last 'End If' highlighted, when I click okay it highlights in
yellow the very first line starting the function.


All Sub and Function procedures must be terminated by an End
statement. Add the line:

End Function

after the last End If

Normally, I would expect Access to supply the End statement
automatically, but maybe you did something funny when
entering the code.
 
R

rjohannes

I entered the End Function line at the end of my code, but when I run the
macro it does nothing. Maybe I have something else wrong. I'm not sure what
to do at this point...
 
J

John W. Vinson

I entered the End Function line at the end of my code, but when I run the
macro it does nothing. Maybe I have something else wrong. I'm not sure what
to do at this point...

This isn't a macro, it's a function; how and where (if at all!) are you
*calling* the function? What's the context?
 
P

PieterLinden via AccessMonster.com

John said:
This isn't a macro, it's a function; how and where (if at all!) are you
*calling* the function? What's the context?

Umm.... I'm calling it on the telephone... but I only have 6 digits... is
that a problem?
 
M

Marshall Barton

rjohannes said:
I entered the End Function line at the end of my code, but when I run the
macro it does nothing. Maybe I have something else wrong. I'm not sure what
to do at this point...


OK, one problem solved, on to the next problem -;)

"Does nothing" is about as clueless as it gets when you want
someone to help you find a problem.

I suspect that there may be a clue in what you did "when I
run the macro". Please give us details about what you did
and what happened.
 
R

rjohannes

Okay, I was trying to make a form that when information is typed into it,
return a report of the requested information based on a query. I found out
the problem that "did nothing" was that I had a parameter set into the query
that didn't need to be there. Once I got rid of that everything worked
smoothly.

But I have a different question about the query...I can't seem to figure out
how to have criteria that is and/or. It is setup now as [Forms]![City
Form]![txtCity] or [Forms]![City Form]![txtServiceLevel] or [Forms]![City
Form]![txtATS/STS]. I want to be able to, in the form, use one or all of the
criteria to get the results. EX: Search for city Maple Plain, Service Level
WC.
 
M

Marshall Barton

rjohannes said:
But I have a different question about the query...I can't seem to figure out
how to have criteria that is and/or. It is setup now as [Forms]![City
Form]![txtCity] or [Forms]![City Form]![txtServiceLevel] or [Forms]![City
Form]![txtATS/STS]. I want to be able to, in the form, use one or all of the
criteria to get the results. EX: Search for city Maple Plain, Service Level


What fields do you want to get which criteria?

How do you want them ANDed and ORed together?

As far as how to do AND and OR, if you look at the query
designer, you will see the Criteria row and you put a
condition under the field that the condition applies to.
All these conditions will be ANDed together.

Under the criteria row you will see the Or row where you can
put alternate conditionz for the same or different set of
fields. All the conditions in the Or row will be ANDed
together. The Criteria set of conditions will be ORed with
the Or set of conditions.

In other words when you want a set of conditions to be ANDed
together, put them in the same row. When you want to OR
another set of conditions, put them in the OR ROW. If you
have more than two sets of conditions to OR use additional
rows under the OR row.

All that confusion can be avoided by switching the query to
SQL view and putting all the condition expressions in the
WHERE clause using AND and OR with parenthesis exactly as
you want them.
 

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