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 / New Users / October 2007

Tip: Looking for answers? Try searching our database.

Forms and Queries

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arlene - 01 Oct 2007 13:36 GMT
Please can you help me as I am trying to run a query by clicking in a combi
box drop down. For example in the combi box I have a List Available, In
stock, Awaiting Stock. What I would like to do is when you click on available
in the combi box I could have a report of every thing that is availble and so
on with In Stock Etc.
Ken Sheridan - 01 Oct 2007 19:02 GMT
I'd suggest having the combo box in an unbound form and within that form put
a subform, in continuous form or datasheet view, based on a query which lists
ALL items, whether available, in stock etc.

For the subform control in the main unbound form set the LinkMasterFields
property to the name of the combo box, and the LinkChildFields property to
the name of the field in the subform's query which contains the values which
correspond with those in the combo box's list, i.e.  'available', 'in stock'
etc.

When you select an item in the combo box the subform should then
automatically show only those rows which match the selection in the combo box.

If you also want to print a report of the items then also create  a report
based on the same query as the subform and add a button to the main form with
code along the following lines in its Click event procedure:

Const conMESSAGE = "Please select an item from the list first."
Dim strCriteria As String
Dim ctrl As Control

Set ctrl = Me.YourComboBox

' make sure an item has been selected
' in the combo box
If Not IsNull(ctrl) Then
  strCriteria = "Availability = """ & ctrl & """"
  ' print report filtered to selected availability
  DoCmd.OpenReport "YourReport", WhereCondtion:=strCriteria
Else
    MsgBox conMESSAGE, vbExclamation, "Invalid Operation"
End If

In the above example Availability would be the name of the field in the
table, so should be changed to its actual name.  You'd also need to change
YourComboBox, YourTable and YourReport to their actual names.  Remember than
any object names which include spaces or other special characters must be
wrapped in brackets [like this].

If you want to preview a report rather than print it change the relevant
line to:

DoCmd.OpenReport "YourReport", View:= acViewPreview,
WhereCondtion:=strCriteria

You could of course have two buttons, one to print the report and one to
preview it.

Ken Sheridan
Stafford, England

> Please can you help me as I am trying to run a query by clicking in a combi
> box drop down. For example in the combi box I have a List Available, In
> stock, Awaiting Stock. What I would like to do is when you click on available
> in the combi box I could have a report of every thing that is availble and so
> on with In Stock Etc.
Arlene - 08 Oct 2007 14:33 GMT
Ken,

Thank you for replying to E-mail it has been very usefull but I have a
slight Problem as when I try to preview the report it Does not like the
Phrase WhereCondtion:= in the code. Please can you help me with this.

Many Thanks

Arlene Clark

> I'd suggest having the combo box in an unbound form and within that form put
> a subform, in continuous form or datasheet view, based on a query which lists
[quoted text clipped - 52 lines]
> > in the combi box I could have a report of every thing that is availble and so
> > on with In Stock Etc.
John W. Vinson - 08 Oct 2007 17:12 GMT
>Thank you for replying to E-mail it has been very usefull but I have a
>slight Problem as when I try to preview the report it Does not like the
>Phrase WhereCondtion:= in the code. Please can you help me with this.

Please copy and paste your actual code and the error message. Neither Ken nor
anyone on the newsgroup can see your screen.

            John W. Vinson [MVP]
Arlene - 09 Oct 2007 07:54 GMT
Sorry Please find the code below. The Combo box name is Combo1, The report is
named Status and my Table name is Status Table.

Const conMESSAGE = "Please select an item from the list first."
Dim strCriteria As String
Dim ctrl As Control

Set ctrl = Me.Combo1

' make sure an item has been selected
' in the combo box
If Not IsNull(ctrl) Then
  strCriteria = "Available = """ & ctrl & """"
  ' Preview report filtered to selected availability
  DoCmd.OpenReport "Status ", acViewPreview, WhereCondtion:=strCriteria
  Else
   MsgBox conMESSAGE, vbExclamation, "Invalid Operation"
End If

End Sub

> >Thank you for replying to E-mail it has been very usefull but I have a
> >slight Problem as when I try to preview the report it Does not like the
[quoted text clipped - 4 lines]
>
>              John W. Vinson [MVP]
John Spencer - 09 Oct 2007 11:59 GMT
DoCmd.OpenReport "Status ", acViewPreview, WhereCondtion:=strCriteria

WhereCondition NOT WhereCondtion   (notice the missing "i")

Of course, I usually use the alternate construction
  DoCmd.OpenReport "Status ", acViewPreview, , strCriteria
Signature

John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.

> Sorry Please find the code below. The Combo box name is Combo1, The report
> is
[quoted text clipped - 31 lines]
>>
>>              John W. Vinson [MVP]
Arlene - 09 Oct 2007 14:38 GMT
Hi John, Thanks it is working now but I have another Problem when I run the
report I have a box with Invalid Operation Please select an item from the
List First  come up in front of the report. Sorry but I have another question
how can I do the same but in a query form rather than a report form.

>    DoCmd.OpenReport "Status ", acViewPreview, WhereCondtion:=strCriteria
>
[quoted text clipped - 37 lines]
> >>
> >>              John W. Vinson [MVP]
John Spencer - 10 Oct 2007 15:54 GMT
Sorry, I am not sure I understand your latest set of questions.

I have no idea why you are getting the Invalid Operation, Please select and
item from the List First message.

Are you selecting something in Combo1 before you ?click on a button? to run
the report?
Did you drop the If ... Then ... Else ... End If structure in your code?

Private Sub ?????????????
Const conMESSAGE = "Please select an item from the list first."
Dim strCriteria As String
Dim ctrl As Control

Set ctrl = Me.Combo1

' make sure an item has been selected
' in the combo box

If Not IsNull(ctrl) Then
  strCriteria = "Available = """ & ctrl & """"
  ' Preview report filtered to selected availability
  DoCmd.OpenReport "Status ", acViewPreview, WhereCondtion:=strCriteri
Else
   MsgBox conMESSAGE, vbExclamation, "Invalid Operation"
End If

End Sub

There is no such thing as a query form.  Do you mean you want to filter the
records that a form displays?  OR do you want to filter the records that a
query is displaying in Datasheet view?

Signature

John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.

> Hi John, Thanks it is working now but I have another Problem when I run
> the
[quoted text clipped - 4 lines]
>
>>    DoCmd.OpenReport "Status ", acViewPreview, WhereCondtion:=strCriteria
Arlene - 30 Oct 2007 15:44 GMT
Please could you help as I seem to be doing something wrong. I have enter the
code below and the following error appears. Syntax error (Missing operator)
in query Expression (Billing Status =In Store (Off)”””).

The  Code is

Const conMESSAGE = "Please select an item from the list first."
Dim strCriteria As String
Dim ctrl As Control

Set ctrl = Me.Combo200

' make sure an item has been selected in the combo box

If Not IsNull(ctrl) Then
  strCriteria = "Billing Status = """ & ctrl & """""
  ' Preview report filtered to selected Billing Status
  DoCmd.OpenReport "Billing Status", acViewPreview, =strCriteria
Else
   MsgBox conMESSAGE, vbExclamation, "Invalid Operation"
End If
End Sub

The Form Name is Billing Status Table and has a Field Name of Billing Status
Which has a list below of
In Store (Off), Not In Store (On), Terminate.

The Query is also named Billing Status
The Report Name is Billing Status

> Sorry, I am not sure I understand your latest set of questions.
>
[quoted text clipped - 37 lines]
> >
> >>    DoCmd.OpenReport "Status ", acViewPreview, WhereCondtion:=strCriteria
John Spencer - 30 Oct 2007 16:43 GMT
Now you know one reason that having spaces in field and table names is a bad
idea.

Try changing the line to
  strCriteria = "[Billing Status] = """ & ctrl & """""

Const conMESSAGE = "Please select an item from the list first."
Dim strCriteria As String
Dim ctrl As Control

Set ctrl = Me.Combo200

' make sure an item has been selected in the combo box

If Not IsNull(ctrl) Then

  strCriteria = "[Billing Status] = """ & ctrl & """""

  ' Preview report filtered to selected Billing Status
  DoCmd.OpenReport "Billing Status", acViewPreview, =strCriteria
Else
   MsgBox conMESSAGE, vbExclamation, "Invalid Operation"
End If
End Sub

Signature

John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.

> Please could you help as I seem to be doing something wrong. I have enter
> the
[quoted text clipped - 76 lines]
>> >>    DoCmd.OpenReport "Status ", acViewPreview,
>> >> WhereCondtion:=strCriteria
Arlene - 31 Oct 2007 15:13 GMT
John  Thanks for patience and Help and sorry for troubling you again but now
I have this error coming up.
Syntax error in string query Expression ([Billing Status] =In Store (Off)""").

> Now you know one reason that having spaces in field and table names is a bad
> idea.
[quoted text clipped - 101 lines]
> >> >>    DoCmd.OpenReport "Status ", acViewPreview,
> >> >> WhereCondtion:=strCriteria
Douglas J. Steele - 31 Oct 2007 15:26 GMT
The original suggestion appears to have had one too many double quotes:

strCriteria = "[Billing Status] = """ & ctrl & """"

That's three double quotes before & ctrl &, and four double quotes after.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> John  Thanks for patience and Help and sorry for troubling you again but
> now
[quoted text clipped - 117 lines]
>> >> >>    DoCmd.OpenReport "Status ", acViewPreview,
>> >> >> WhereCondtion:=strCriteria
Arlene - 31 Oct 2007 15:51 GMT
Douglas,

Thanks for your help as it is much appreciated.

Arlene

> The original suggestion appears to have had one too many double quotes:
>
[quoted text clipped - 123 lines]
> >> >> >>    DoCmd.OpenReport "Status ", acViewPreview,
> >> >> >> WhereCondtion:=strCriteria
Arlene - 31 Oct 2007 15:52 GMT
John,

Thanks for your help as it is much appreciated.

Arlene

> Now you know one reason that having spaces in field and table names is a bad
> idea.
[quoted text clipped - 101 lines]
> >> >>    DoCmd.OpenReport "Status ", acViewPreview,
> >> >> WhereCondtion:=strCriteria
Arlene - 09 Oct 2007 08:34 GMT
Sorry forgot to post the error Message. Named argument not found.
WhereCondtion:=

> >Thank you for replying to E-mail it has been very usefull but I have a
> >slight Problem as when I try to preview the report it Does not like the
[quoted text clipped - 4 lines]
>
>              John W. Vinson [MVP]
 
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.