PC Review


Reply
Thread Tools Rate Thread

Allen Brown's Multiselect Database

 
 
Confused
Guest
Posts: n/a
 
      16th Apr 2009
http://allenbrowne.com/ser-50.html

At this site, how do I do this same thing except open a new form based on
the query it performs instead of opening a report?

This uses the Northwind database and just wonder how it knows how to open a
report instead of a query? Because there is a query named the same thing as
the report it opens.
 
Reply With Quote
 
 
 
 
Arvin Meyer MVP
Guest
Posts: n/a
 
      16th Apr 2009
"Confused" <(E-Mail Removed)> wrote in message
news:FCF70013-1819-458D-9375-(E-Mail Removed)...
> http://allenbrowne.com/ser-50.html
>
> At this site, how do I do this same thing except open a new form based on
> the query it performs instead of opening a report?
>
> This uses the Northwind database and just wonder how it knows how to open
> a
> report instead of a query? Because there is a query named the same thing
> as
> the report it opens.


It would have to be the underlying code which tells it to open a report.
Like:

DoCmd.OpenReport "Whatever", acPreview

There is definitely a problem naming both a table and a query the same
because they can be called the same way. That's one of the reasons that most
developers use a naming convention that separates the 2, like tblWhatever
and qryWhatever.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


 
Reply With Quote
 
Confused
Guest
Posts: n/a
 
      17th Apr 2009
On this code do you know what do I need to do to change it to open a form
based on the query performed?



The code

--------------------------------------------------------------------------------

Private Sub cmdPreview_Click()
On Error GoTo Err_Handler
'Purpose: Open the report filtered to the items selected in the list box.
'Author: Allen J Browne, 2004. http://allenbrowne.com
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.

'strDelim = """" 'Delimiter appropriate to field type. See
note 1.
strDoc = "Products by Category"

'Loop through the ItemsSelected in the list box.
With Me.lstCategory
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text in the visible
column. See note 2.
strDescrip = strDescrip & """" & .Column(1, varItem) & """, "
End If
Next
End With

'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[CategoryID] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Categories: " & Left$(strDescrip, lngLen)
End If
End If

'Report will not filter if open, so close it. For Access 97, see note 3.
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If

'Omit the last argument for Access 2000 and earlier. See note 4.
DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler
End Sub

"Arvin Meyer MVP" wrote:

> "Confused" <(E-Mail Removed)> wrote in message
> news:FCF70013-1819-458D-9375-(E-Mail Removed)...
> > http://allenbrowne.com/ser-50.html
> >
> > At this site, how do I do this same thing except open a new form based on
> > the query it performs instead of opening a report?
> >
> > This uses the Northwind database and just wonder how it knows how to open
> > a
> > report instead of a query? Because there is a query named the same thing
> > as
> > the report it opens.

>
> It would have to be the underlying code which tells it to open a report.
> Like:
>
> DoCmd.OpenReport "Whatever", acPreview
>
> There is definitely a problem naming both a table and a query the same
> because they can be called the same way. That's one of the reasons that most
> developers use a naming convention that separates the 2, like tblWhatever
> and qryWhatever.
> --
> Arvin Meyer, MCP, MVP
> http://www.datastrat.com
> http://www.mvps.org/access
> http://www.accessmvp.com
>
>
>

 
Reply With Quote
 
Arvin Meyer MVP
Guest
Posts: n/a
 
      17th Apr 2009
See this code:

'Omit the last argument for Access 2000 and earlier. See note 4.
DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip

Change it to:
DoCmd.OpenForm strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Confused" <(E-Mail Removed)> wrote in message
news:2D3EDA1F-ACF3-4FCA-B31E-(E-Mail Removed)...
> On this code do you know what do I need to do to change it to open a form
> based on the query performed?
>
>
>
> The code
>
> --------------------------------------------------------------------------------
>
> Private Sub cmdPreview_Click()
> On Error GoTo Err_Handler
> 'Purpose: Open the report filtered to the items selected in the list
> box.
> 'Author: Allen J Browne, 2004. http://allenbrowne.com
> Dim varItem As Variant 'Selected items
> Dim strWhere As String 'String to use as WhereCondition
> Dim strDescrip As String 'Description of WhereCondition
> Dim lngLen As Long 'Length of string
> Dim strDelim As String 'Delimiter for this field type.
> Dim strDoc As String 'Name of report to open.
>
> 'strDelim = """" 'Delimiter appropriate to field type. See
> note 1.
> strDoc = "Products by Category"
>
> 'Loop through the ItemsSelected in the list box.
> With Me.lstCategory
> For Each varItem In .ItemsSelected
> If Not IsNull(varItem) Then
> 'Build up the filter from the bound column (hidden).
> strWhere = strWhere & strDelim & .ItemData(varItem) &
> strDelim & ","
> 'Build up the description from the text in the visible
> column. See note 2.
> strDescrip = strDescrip & """" & .Column(1, varItem) & """,
> "
> End If
> Next
> End With
>
> 'Remove trailing comma. Add field name, IN operator, and brackets.
> lngLen = Len(strWhere) - 1
> If lngLen > 0 Then
> strWhere = "[CategoryID] IN (" & Left$(strWhere, lngLen) & ")"
> lngLen = Len(strDescrip) - 2
> If lngLen > 0 Then
> strDescrip = "Categories: " & Left$(strDescrip, lngLen)
> End If
> End If
>
> 'Report will not filter if open, so close it. For Access 97, see note
> 3.
> If CurrentProject.AllReports(strDoc).IsLoaded Then
> DoCmd.Close acReport, strDoc
> End If
>
> 'Omit the last argument for Access 2000 and earlier. See note 4.
> DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
> OpenArgs:=strDescrip
>
> Exit_Handler:
> Exit Sub
>
> Err_Handler:
> If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
> MsgBox "Error " & Err.Number & " - " & Err.Description, ,
> "cmdPreview_Click"
> End If
> Resume Exit_Handler
> End Sub
>
> "Arvin Meyer MVP" wrote:
>
>> "Confused" <(E-Mail Removed)> wrote in message
>> news:FCF70013-1819-458D-9375-(E-Mail Removed)...
>> > http://allenbrowne.com/ser-50.html
>> >
>> > At this site, how do I do this same thing except open a new form based
>> > on
>> > the query it performs instead of opening a report?
>> >
>> > This uses the Northwind database and just wonder how it knows how to
>> > open
>> > a
>> > report instead of a query? Because there is a query named the same
>> > thing
>> > as
>> > the report it opens.

>>
>> It would have to be the underlying code which tells it to open a report.
>> Like:
>>
>> DoCmd.OpenReport "Whatever", acPreview
>>
>> There is definitely a problem naming both a table and a query the same
>> because they can be called the same way. That's one of the reasons that
>> most
>> developers use a naming convention that separates the 2, like tblWhatever
>> and qryWhatever.
>> --
>> Arvin Meyer, MCP, MVP
>> http://www.datastrat.com
>> http://www.mvps.org/access
>> http://www.accessmvp.com
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
For Allen Brown (Argent) Allen Browne Microsoft Access Form Coding 3 1st Dec 2007 01:21 PM
Help Allen Brown!!! Tony Williams Microsoft Access 2 11th Dec 2006 10:38 AM
Allen Brown Tom Ellison Microsoft Access Queries 0 10th Mar 2006 10:31 AM
Allen Brown's Calendars =?Utf-8?B?SmVmZiBD?= Microsoft Access 3 4th May 2005 04:17 PM
multiselect list box - Allen Brown code =?Utf-8?B?Y29hY2hqZWZmZXJ5?= Microsoft Access Forms 1 7th Apr 2005 05:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:21 AM.