PC Review


Reply
Thread Tools Rate Thread

Combobox controlled search

 
 
=?Utf-8?B?U3RldmUgTW9zcw==?=
Guest
Posts: n/a
 
      30th Oct 2007
I have a form with a combobox giving the options of a list of people
"Custodian". On update I wish for the option selected to be used to open a
report with filtered information. the report is a full list of books held by
everybody in my company. instead of writing a query and report for each
person (this an ever expanding list) I wish it to be filtered. I have used
the folloowing code in the past, buit for some reason the report opens blank
(only with headings). I am not sure what each part of the code represents,
can anyone shed light on this for me

Private Sub Combo0_AfterUpdate()
If Len(Trim(Me![Combo0]) & "") > 0 Then
DoCmd.OpenReport "Reportname", acViewPreview, , "[nameofpersonfield]='" &
Me![Combo0].Value & "'"
Else
MsgBox "Enter which person's holdings you require to view"
End If
End Sub
 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2VuIFNoZXJpZGFu?=
Guest
Posts: n/a
 
      30th Oct 2007
Is the value of the combo box the name or a unique ID column? If the latter
(as should be the case) then no rows would be returned in the report as it
would be looking for somebody with a number as their name! Names are
unsuitable keys as they can be duplicated, even within a small environment (I
once worked with two Maggie Taylors), so a numeric key such as an autonumber
is better. If the combo box has a RowSource such as:

SELECT EmployeeID, Employee
FROM Employees
ORDER BY Employee;

and its BoundColumn property is 1, then the value of the combo box will be
the (usually hidden) EmployeeID, in which case the WhereCondition argument of
the OpenReport method should reference this column, e.g.

DoCmd.OpenReport "Reportname", View:=acViewPreview,
WhereCondition:="EmployeeID = " & Me.cboEmployees

The EmployeeID column would need to be included in the report's RecordSource
query of course, even though it would not be shown in the report.

BTW rather than accepting the default names like Combo0 given to controls,
change it to something meaningful like cboEmployees. Note, however, that if
you change the Name property after creating an event procedure for a control
the link between the code and the control will be lost, so you'd need to copy
the body code from the original procedure, delete the whole procedure, and
create a new event procedure, pasting in the original code (and amending it
if it refers to the control by name).

Ken Sheridan
Stafford, England

"Steve Moss" wrote:

> I have a form with a combobox giving the options of a list of people
> "Custodian". On update I wish for the option selected to be used to open a
> report with filtered information. the report is a full list of books held by
> everybody in my company. instead of writing a query and report for each
> person (this an ever expanding list) I wish it to be filtered. I have used
> the folloowing code in the past, buit for some reason the report opens blank
> (only with headings). I am not sure what each part of the code represents,
> can anyone shed light on this for me
>
> Private Sub Combo0_AfterUpdate()
> If Len(Trim(Me![Combo0]) & "") > 0 Then
> DoCmd.OpenReport "Reportname", acViewPreview, , "[nameofpersonfield]='" &
> Me![Combo0].Value & "'"
> Else
> MsgBox "Enter which person's holdings you require to view"
> End If
> End Sub


 
Reply With Quote
 
=?Utf-8?B?U3RldmUgTW9zcw==?=
Guest
Posts: n/a
 
      31st Oct 2007
Thanks ken I will give it a go.

"Ken Sheridan" wrote:

> Is the value of the combo box the name or a unique ID column? If the latter
> (as should be the case) then no rows would be returned in the report as it
> would be looking for somebody with a number as their name! Names are
> unsuitable keys as they can be duplicated, even within a small environment (I
> once worked with two Maggie Taylors), so a numeric key such as an autonumber
> is better. If the combo box has a RowSource such as:
>
> SELECT EmployeeID, Employee
> FROM Employees
> ORDER BY Employee;
>
> and its BoundColumn property is 1, then the value of the combo box will be
> the (usually hidden) EmployeeID, in which case the WhereCondition argument of
> the OpenReport method should reference this column, e.g.
>
> DoCmd.OpenReport "Reportname", View:=acViewPreview,
> WhereCondition:="EmployeeID = " & Me.cboEmployees
>
> The EmployeeID column would need to be included in the report's RecordSource
> query of course, even though it would not be shown in the report.
>
> BTW rather than accepting the default names like Combo0 given to controls,
> change it to something meaningful like cboEmployees. Note, however, that if
> you change the Name property after creating an event procedure for a control
> the link between the code and the control will be lost, so you'd need to copy
> the body code from the original procedure, delete the whole procedure, and
> create a new event procedure, pasting in the original code (and amending it
> if it refers to the control by name).
>
> Ken Sheridan
> Stafford, England
>
> "Steve Moss" wrote:
>
> > I have a form with a combobox giving the options of a list of people
> > "Custodian". On update I wish for the option selected to be used to open a
> > report with filtered information. the report is a full list of books held by
> > everybody in my company. instead of writing a query and report for each
> > person (this an ever expanding list) I wish it to be filtered. I have used
> > the folloowing code in the past, buit for some reason the report opens blank
> > (only with headings). I am not sure what each part of the code represents,
> > can anyone shed light on this for me
> >
> > Private Sub Combo0_AfterUpdate()
> > If Len(Trim(Me![Combo0]) & "") > 0 Then
> > DoCmd.OpenReport "Reportname", acViewPreview, , "[nameofpersonfield]='" &
> > Me![Combo0].Value & "'"
> > Else
> > MsgBox "Enter which person's holdings you require to view"
> > End If
> > End Sub

>

 
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
Combobox search smcgrath via AccessMonster.com Microsoft Access Forms 0 21st Sep 2006 08:42 PM
Help with a Combobox search jamie.rowland@shell.com Microsoft Access Forms 1 22nd Aug 2006 05:00 PM
ComboBox Search with Like =?Utf-8?B?QW1hbmRhIEJ5cm5l?= Microsoft Access Form Coding 2 29th Jun 2006 06:30 PM
ComboBox auto search =?Utf-8?B?Q2hyaXM=?= Microsoft ADO .NET 1 12th Mar 2004 01:33 PM
xp search combobox Saso Zagoranski Microsoft C# .NET 1 24th Aug 2003 09:59 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:41 AM.