using WHERE in DOCMD

J

Jason M Canady

I am using hte following from a command button from a form to launch a
report (see ealier posts...) I thought that I could use the filter property
to retrieve only the results that I needed for my report however that did
not seem to work as I intended. I had early success with WHERE, but now my
SQL is getting more complicated and I am returning an "Object Required"
error when the command is run.

Can someone see a problem that I cannot?

Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

Dim stDocName As String

stDocName = "Annual WorkOrders"
DoCmd.OpenReport stDocName, acPreview, ,
(((WorkOrders.RepeatIntervalamount) = 1) And
((WorkOrders.RepeatIntervalunit) = "yr") And ((equipment.CategoryID) <> 3))
DoCmd.Maximize
DoCmd.RunCommand acCmdZoom100

Exit_Command10_Click:
Exit Sub

Err_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click

End Sub

I could get it to work when I was only using "CategoryID<>3", now...

Any assistance would be most helpful.

Thanks, Jason
 
G

Gary Miller

Jason,

I think the problem is as simple as forgetting to put quotes
around your Where SQL string. When you do this you will need
to change the interior double quotes to singles...

DoCmd.OpenReport stDocName, acPreview, ,
"(((WorkOrders.RepeatIntervalamount) = 1) And
WorkOrders.RepeatIntervalunit) = 'yr') And
((equipment.CategoryID) <> 3))"


--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
Jason M Canady said:
I am using hte following from a command button from a form to launch a
report (see ealier posts...) I thought that I could use the filter property
to retrieve only the results that I needed for my report however that did
not seem to work as I intended. I had early success with WHERE, but now my
SQL is getting more complicated and I am returning an "Object Required"
error when the command is run.

Can someone see a problem that I cannot?

Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

Dim stDocName As String

stDocName = "Annual WorkOrders"
DoCmd.OpenReport stDocName, acPreview, ,
(((WorkOrders.RepeatIntervalamount) = 1) And
((WorkOrders.RepeatIntervalunit) = "yr") And
 
J

Jason M Canady

Geez! I kney it was simple... I tried the quotes but ran into problems with
the inner quotes like you suggested I would. I wish learning didn't have to
be so painfull sometimes!

Thanks VERY much

Jason
 
G

Gary Miller

Sometimes it's those little details that bite the worst.
You're welcome.

--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
 

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