?
Solved

Differentiating names form and subform

Posted on 2015-02-16
5
Medium Priority
?
168 Views
Last Modified: 2015-02-16
Hi all,

I am having difficulty distinguishing between two same surnamed individuals.

The sample I am attaching provides my dilemma.

I have two same surnamed individuals but when I highlight them in the form the same data appears in the subform.

Grateful if someone would assist.

Thanks
SP-ver-EE2.mdb
0
Comment
Question by:PipMic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Simon
ID: 40613020
It sounds like the master<=>child link between the form and subform is currently just on surname. You need to add another field to distinguish records with the same surname.

Edit: Actually I see that you're not using a subform, but a series of textboxes  populated by the on-click event of the list_staff listbox. For your current method you need to include the forename in the DLookup functions that you're using.
0
 

Author Comment

by:PipMic
ID: 40613037
I have the following two criteria:-

What should I change?  Not too clear!

Private Sub list_staff_Click()
txt_Grade = DLookup("[Grade]", "tbl_Officer", "[Surname] = Forms![frm_Directory]![list_Staff]")
txt_Section = DLookup("[Section]", "tbl_Officer", "[Surname] = Forms![frm_Directory]![list_Staff]")
txt_Centrex = DLookup("[Centrex]", "tbl_Officer", "[Surname] = Forms![frm_Directory]![list_Staff]")
txt_directline = DLookup("[DirectLine]", "tbl_Officer", "[Surname] = Forms![frm_Directory]![list_Staff]")
txt_email = DLookup("[Email]", "tbl_Officer", "[Surname] = Forms![frm_Directory]![list_Staff]")


SELECT DISTINCTROW tbl_Officer.Surname, tbl_Officer.Forename FROM tbl_Officer ORDER BY tbl_Officer.Surname;
0
 
LVL 18

Accepted Solution

by:
Simon earned 2000 total points
ID: 40613060
See how I've changed the DLookups. Tested and working.

Private Sub list_staff_Click()
txt_Grade = DLookup("[Grade]", "tbl_Officer", "[Surname] = '" & Me.list_staff.Column(0) & "' and [forename] = '" & Me.list_staff.Column(1) & "'")
txt_Section = DLookup("[Section]", "tbl_Officer", "[Surname] = '" & Me.list_staff.Column(0) & "' and [forename] = '" & Me.list_staff.Column(1) & "'")
txt_Centrex = DLookup("[Centrex]", "tbl_Officer", "[Surname] = '" & Me.list_staff.Column(0) & "' and [forename] = '" & Me.list_staff.Column(1) & "'")
txt_directline = DLookup("[DirectLine]", "tbl_Officer", "[Surname] = '" & Me.list_staff.Column(0) & "' and [forename] = '" & Me.list_staff.Column(1) & "'")
txt_email = DLookup("[Email]", "tbl_Officer", "[Surname] = '" & Me.list_staff.Column(0) & "' and [forename] = '" & Me.list_staff.Column(1) & "'")
END SUB

Open in new window


Note: If your tbl_Officer has many rows, these multiple DLookups aren't going to be the best performing way of retrieving the data. If you want to stay with Dlookups, you could include the PID as a zero-width column in your listbox and use that as the criteria, and a faster method would be to create a recordset based on a query like 'select grade,section,centrex,directline,email from tbl_officer where PID =' & me.staff_list.column(x)
and then set your textboxes to the appropriate columns of the recordset.
You could also use a subform linked to the main form by PID.
However, the above code works and switching to recordset or subform is a larger change to your design and subject for another question if necessary.
0
 

Author Comment

by:PipMic
ID: 40613084
Thanks....

grateful for your answer...
0
 
LVL 18

Expert Comment

by:Simon
ID: 40613087
No problem. I may have edited it since you saw it. I think our posts crossed.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question