A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

List Box



 
 
Thread Tools Display Modes
  #1  
Old August 23rd, 2004, 05:18 AM
Andrew C
external usenet poster
 
Posts: n/a
Default List Box

Hi

On the side of my form i have a list box and when you
click on the client names it brings there details up.

Only problem i have is that if two people have the same
surname it picks up the first person details. I can
change it to pick up the first name but that doesnt solve
my problem.

Each client has an ID Number is it possible to use that in
the list. If so can someone help me out

Thanks

Andrew
  #2  
Old August 23rd, 2004, 09:26 AM
Nikos Yannacopoulos
external usenet poster
 
Posts: n/a
Default

Andrew,

Having the ID number in your table is a very good start. As a general rule,
using names as a PK is bad practice (but also a very common mistake among
new users). Having said that, obviously you need to change your desing so it
utilizes the ID field, and looks up the details based on that. The trick is
to make the listbox display the surname and first name, while it actually
returns the ID field. To do that, select the listbox in form design, and
change its rowsource property (easiest way: invoke thequery builder) so it
selects the ID field, surname field, first name field; leave the bound
column property to 1, then go to the Format tab, set the column count
property to 3 if different, and specify column widths in the pertinent
property, making sure the first one is 0 so it doesn't show in the list.
That's all there is to it! Now you can use the reference to the listbox to
DLookup your detail textboxes on the ID field.

HTH,
Nikos



"Andrew C" wrote in message
...
Hi

On the side of my form i have a list box and when you
click on the client names it brings there details up.

Only problem i have is that if two people have the same
surname it picks up the first person details. I can
change it to pick up the first name but that doesnt solve
my problem.

Each client has an ID Number is it possible to use that in
the list. If so can someone help me out

Thanks

Andrew



  #3  
Old August 23rd, 2004, 02:06 PM
Sandra Daigle
external usenet poster
 
Posts: n/a
Default

Hi Andrew,

It sounds like the ID field needs to be included in the rowsource of your
listbox. If the Id number is the field that the users would recognize to
allow them to distinguish between two "John Smith" records, then the Id
field should be included in the rowsource of the listbox and should not be
hidden. If there are other fields that allow the user to make the selection
then they should be included and displayed. Are you using the AfterUpdate
event of the listbox to navigate to the selected record? Or are the results
displayed in a subform which uses the listbox in the LinkMasterFields?

Either way, be sure that the search field(s) or linking field(s) represent a
Unique Index to the table. If you use a single numeric primary key field
then this is the easiest choice for record selection.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Andrew C wrote:
Hi

On the side of my form i have a list box and when you
click on the client names it brings there details up.

Only problem i have is that if two people have the same
surname it picks up the first person details. I can
change it to pick up the first name but that doesnt solve
my problem.

Each client has an ID Number is it possible to use that in
the list. If so can someone help me out

Thanks

Andrew



  #4  
Old August 24th, 2004, 07:45 AM
Andrew C
external usenet poster
 
Posts: n/a
Default

I did that and it wont select anything now. Could the
problem be the the ID Number is an autonumber and not a
text field.


-----Original Message-----
Andrew,

Having the ID number in your table is a very good start.

As a general rule,
using names as a PK is bad practice (but also a very

common mistake among
new users). Having said that, obviously you need to

change your desing so it
utilizes the ID field, and looks up the details based on

that. The trick is
to make the listbox display the surname and first name,

while it actually
returns the ID field. To do that, select the listbox in

form design, and
change its rowsource property (easiest way: invoke

thequery builder) so it
selects the ID field, surname field, first name field;

leave the bound
column property to 1, then go to the Format tab, set the

column count
property to 3 if different, and specify column widths in

the pertinent
property, making sure the first one is 0 so it doesn't

show in the list.
That's all there is to it! Now you can use the reference

to the listbox to
DLookup your detail textboxes on the ID field.

HTH,
Nikos



"Andrew C" wrote in

message
...
Hi

On the side of my form i have a list box and when you
click on the client names it brings there details up.

Only problem i have is that if two people have the same
surname it picks up the first person details. I can
change it to pick up the first name but that doesnt

solve
my problem.

Each client has an ID Number is it possible to use that

in
the list. If so can someone help me out

Thanks

Andrew



.

  #5  
Old August 24th, 2004, 11:51 AM
Nikos Yannacopoulos
external usenet poster
 
Posts: n/a
Default

Andrew,

I would say the first thing to do is to make sure the listbox returns what
it is supposed to. To check, press Ctrl+G while the form is open and a name
is selected in the listbox; this will take you to the immediate window of
the VB editor. Type the following in the

?Forms![MyFormName]![ListBoxName]

using the actual form and listbox name instead of my generic ones, and press
enter. Whatever the lsitbox returns will ne printed in the next line of the
immediate window, so you'll know. Is it indeed the value of the autonumber
field corresponding to the selected name?
If that's OK, then you need to check your DLookups, which should look
something like:

DLookup("[SomeField]","TableName","[IDFieldName]=" &
Forms![MyFormName]![ListBoxName])

If your DLookups were previously using a text field, it may be that there
are some extra quotes for text left around the listbox reference in the
expressions; if that's the case, they should be removed since the ID field
is numeric.

HTH,
Nikos

"Andrew C" wrote in message
...
I did that and it wont select anything now. Could the
problem be the the ID Number is an autonumber and not a
text field.


-----Original Message-----
Andrew,

Having the ID number in your table is a very good start.

As a general rule,
using names as a PK is bad practice (but also a very

common mistake among
new users). Having said that, obviously you need to

change your desing so it
utilizes the ID field, and looks up the details based on

that. The trick is
to make the listbox display the surname and first name,

while it actually
returns the ID field. To do that, select the listbox in

form design, and
change its rowsource property (easiest way: invoke

thequery builder) so it
selects the ID field, surname field, first name field;

leave the bound
column property to 1, then go to the Format tab, set the

column count
property to 3 if different, and specify column widths in

the pertinent
property, making sure the first one is 0 so it doesn't

show in the list.
That's all there is to it! Now you can use the reference

to the listbox to
DLookup your detail textboxes on the ID field.

HTH,
Nikos



"Andrew C" wrote in

message
...
Hi

On the side of my form i have a list box and when you
click on the client names it brings there details up.

Only problem i have is that if two people have the same
surname it picks up the first person details. I can
change it to pick up the first name but that doesnt

solve
my problem.

Each client has an ID Number is it possible to use that

in
the list. If so can someone help me out

Thanks

Andrew



.



  #6  
Old August 26th, 2004, 02:35 AM
Andrew C
external usenet poster
 
Posts: n/a
Default

Ok

i think the problem maybe with the Dlookup section. I
have had a look through and cant find anything related to
Dlookup.

I use an afterupdate which has the following in it.

Private Sub List101_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.Findfirst "[Lastname] = '" & Me![List101] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Other than that i need more help. Thanks for being
patient with me.

Andrew
-----Original Message-----
Andrew,

I would say the first thing to do is to make sure the

listbox returns what
it is supposed to. To check, press Ctrl+G while the form

is open and a name
is selected in the listbox; this will take you to the

immediate window of
the VB editor. Type the following in the

?Forms![MyFormName]![ListBoxName]

using the actual form and listbox name instead of my

generic ones, and press
enter. Whatever the lsitbox returns will ne printed in

the next line of the
immediate window, so you'll know. Is it indeed the value

of the autonumber
field corresponding to the selected name?
If that's OK, then you need to check your DLookups, which

should look
something like:

DLookup("[SomeField]","TableName","[IDFieldName]=" &
Forms![MyFormName]![ListBoxName])

If your DLookups were previously using a text field, it

may be that there
are some extra quotes for text left around the listbox

reference in the
expressions; if that's the case, they should be removed

since the ID field
is numeric.

HTH,
Nikos

"Andrew C" wrote in

message
...
I did that and it wont select anything now. Could the
problem be the the ID Number is an autonumber and not a
text field.


-----Original Message-----
Andrew,

Having the ID number in your table is a very good

start.
As a general rule,
using names as a PK is bad practice (but also a very

common mistake among
new users). Having said that, obviously you need to

change your desing so it
utilizes the ID field, and looks up the details based

on
that. The trick is
to make the listbox display the surname and first name,

while it actually
returns the ID field. To do that, select the listbox in

form design, and
change its rowsource property (easiest way: invoke

thequery builder) so it
selects the ID field, surname field, first name field;

leave the bound
column property to 1, then go to the Format tab, set

the
column count
property to 3 if different, and specify column widths

in
the pertinent
property, making sure the first one is 0 so it doesn't

show in the list.
That's all there is to it! Now you can use the

reference
to the listbox to
DLookup your detail textboxes on the ID field.

HTH,
Nikos



"Andrew C" wrote

in
message
...
Hi

On the side of my form i have a list box and when you
click on the client names it brings there details up.

Only problem i have is that if two people have the

same
surname it picks up the first person details. I can
change it to pick up the first name but that doesnt

solve
my problem.

Each client has an ID Number is it possible to use

that
in
the list. If so can someone help me out

Thanks

Andrew


.



.

  #7  
Old August 26th, 2004, 11:45 AM
Nikos Yannacopoulos
external usenet poster
 
Posts: n/a
Default

Andrew,

OK, we're getting there. DLookup was just an assumption on my part, while
you've been doing this in a more "professional" way.
What's happening is your code is trying to match the current value of the
listbox to the value of field Lastname (as was the original setup), while
the listbox now returns the person's ID, so it obviously fails. To fix this,
you need to change your code to:

Private Sub List101_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.Findfirst "[ID Number] = " & Me![List101]
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

so it tries to match the correct field. I have assumed that the field name
is 'ID Number', if different change accordingly.
Note that I have removed the extra quotes around the Me![List101]; this is
assuming the ID number field is indeed numeric. If by any chance it is text,
then it should be:
rs.Findfirst "[ID Number] = '" & Me![List101] & "'"

Last, but not least, yo should make sure your form's recordset includes the
ID Number field. If the recordset is the people table itself then it
definitely does; if it is a query, check the query design to make sure it is
included, or add it otherwise.

HTH,
Nikos


"Andrew C" wrote in message
...
Ok

i think the problem maybe with the Dlookup section. I
have had a look through and cant find anything related to
Dlookup.

I use an afterupdate which has the following in it.

Private Sub List101_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.Findfirst "[Lastname] = '" & Me![List101] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Other than that i need more help. Thanks for being
patient with me.

Andrew
-----Original Message-----
Andrew,

I would say the first thing to do is to make sure the

listbox returns what
it is supposed to. To check, press Ctrl+G while the form

is open and a name
is selected in the listbox; this will take you to the

immediate window of
the VB editor. Type the following in the

?Forms![MyFormName]![ListBoxName]

using the actual form and listbox name instead of my

generic ones, and press
enter. Whatever the lsitbox returns will ne printed in

the next line of the
immediate window, so you'll know. Is it indeed the value

of the autonumber
field corresponding to the selected name?
If that's OK, then you need to check your DLookups, which

should look
something like:

DLookup("[SomeField]","TableName","[IDFieldName]=" &
Forms![MyFormName]![ListBoxName])

If your DLookups were previously using a text field, it

may be that there
are some extra quotes for text left around the listbox

reference in the
expressions; if that's the case, they should be removed

since the ID field
is numeric.

HTH,
Nikos

"Andrew C" wrote in

message
...
I did that and it wont select anything now. Could the
problem be the the ID Number is an autonumber and not a
text field.


-----Original Message-----
Andrew,

Having the ID number in your table is a very good

start.
As a general rule,
using names as a PK is bad practice (but also a very
common mistake among
new users). Having said that, obviously you need to
change your desing so it
utilizes the ID field, and looks up the details based

on
that. The trick is
to make the listbox display the surname and first name,
while it actually
returns the ID field. To do that, select the listbox in
form design, and
change its rowsource property (easiest way: invoke
thequery builder) so it
selects the ID field, surname field, first name field;
leave the bound
column property to 1, then go to the Format tab, set

the
column count
property to 3 if different, and specify column widths

in
the pertinent
property, making sure the first one is 0 so it doesn't
show in the list.
That's all there is to it! Now you can use the

reference
to the listbox to
DLookup your detail textboxes on the ID field.

HTH,
Nikos



"Andrew C" wrote

in
message
...
Hi

On the side of my form i have a list box and when you
click on the client names it brings there details up.

Only problem i have is that if two people have the

same
surname it picks up the first person details. I can
change it to pick up the first name but that doesnt
solve
my problem.

Each client has an ID Number is it possible to use

that
in
the list. If so can someone help me out

Thanks

Andrew


.



.



 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
extracting a list of members from an email group Russ Valentine [MVP-Outlook] Contacts 5 July 23rd, 2004 08:27 PM
Clear the "Recent Files" list in the hyperlink window Mike Powerpoint 15 July 22nd, 2004 02:51 AM
ItemsSelected in List Box jakeup Using Forms 2 July 16th, 2004 08:03 PM
List Box Size Orf Bartrop New Users 12 May 29th, 2004 02:10 AM
How to make list of unique values? JulieD Worksheet Functions 1 February 26th, 2004 12:25 PM


All times are GMT +1. The time now is 07:15 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.