Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Reports / Printing / January 2006

Tip: Looking for answers? Try searching our database.

Why is this not working (Where Clause)?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ron - 17 Jan 2006 22:51 GMT
I'm not sure why this is not working.  It is returning all records instead
of just the desired criteria:

Report Source is:
 SELECT InvoiceHeader.*, InvoiceDetail.*, Trim(InvoiceHeader!fname) & " " &
Trim(InvoiceHeader!lname) AS Printname FROM InvoiceHeader INNER JOIN
InvoiceDetail ON InvoiceHeader.Recno=InvoiceDetail.InvoiceRecno;

Here is the code from my form's button:
Private Sub btnPrintNow_Click()
Dim stReportname As String
Dim stCriteria As String

stReportname = "rptInvoice"

With Me!Recno
       If Not IsNull(.Value) Then
              strCriteria = "[InvoiceHeader.Recno] = " & .Value
       End If
   End With

MsgBox strCriteria
DoCmd.OpenReport stReportname, acViewPreview, Wherecondition:=stCriteria
End Sub

The msgbox is showing the criteria to be correct, but all the records are
still being selected.
Rick Brandt - 17 Jan 2006 22:54 GMT
> I'm not sure why this is not working.  It is returning all records
> instead of just the desired criteria:
[quoted text clipped - 23 lines]
> The msgbox is showing the criteria to be correct, but all the records
> are still being selected.

Try just...

strCriteria = "Recno = " & .Value

Signature

I don't check the Email account attached
to this message.     Send instead to...
RBrandt    at       Hunter      dot      com

Ron - 17 Jan 2006 23:08 GMT
No, still grabs all

>> I'm not sure why this is not working.  It is returning all records
>> instead of just the desired criteria:
[quoted text clipped - 27 lines]
>
> strCriteria = "Recno = " & .Value
Ron - 18 Jan 2006 00:03 GMT
I also tried "Invoice.recno" to no avail

> No, still grabs all
>
[quoted text clipped - 29 lines]
>>
>> strCriteria = "Recno = " & .Value
Rick Brandt - 18 Jan 2006 00:09 GMT
> I also tried "Invoice.recno" to no avail

Simplify and conquer.  What happens if you use a literal that you know is in the
report's RecordSet?

Like...

strCriteria = "Recno = 123"

Signature

I don't check the Email account attached
to this message.     Send instead to...
RBrandt    at       Hunter      dot      com

Ron - 18 Jan 2006 15:05 GMT
Thanks Rick.  I did put in a literal as you suggested and it worked like a
charm.  So then  I looked again and low and behold, the variable names are
different in my code (I am passing STcriteria but assigning a value to
STRcriteria).  ARGH!

Thanks for the sanity!!

>> I also tried "Invoice.recno" to no avail
>
[quoted text clipped - 4 lines]
>
> strCriteria = "Recno = 123"
Rick Brandt - 18 Jan 2006 19:04 GMT
> Thanks Rick.  I did put in a literal as you suggested and it worked
> like a charm.  So then  I looked again and low and behold, the
> variable names are different in my code (I am passing STcriteria but
> assigning a value to STRcriteria).  ARGH!
>
> Thanks for the sanity!!

Ah, that's why you always want OPTION EXPLICIT at the top of your modules.
If you spell a variable wrong it will catch it with Option Explicit, but
won't otherwise.

Signature

I don't check the Email account attached
to this message.     Send instead to...
RBrandt    at       Hunter      dot      com

Duane Hookom - 18 Jan 2006 00:10 GMT
Try compile your code with Option Explicit.  Then use code like:

Private Sub btnPrintNow_Click()
Dim stReportname As String
Dim stCriteria As String

stReportname = "rptInvoice"

With Me!Recno
       If Not IsNull(.Value) Then
              stCriteria = "[Recno] = " & .Value
       End If
   End With

MsgBox strCriteria
DoCmd.OpenReport stReportname, acViewPreview, , stCriteria
End Sub

Signature

Duane Hookom
MS Access MVP
--

> No, still grabs all
>
[quoted text clipped - 29 lines]
>>
>> strCriteria = "Recno = " & .Value
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.