Solved

Differentiating names form and subform

Posted on 2015-02-16
5
162 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
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:SimonAdept
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:
SimonAdept earned 500 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:SimonAdept
ID: 40613087
No problem. I may have edited it since you saw it. I think our posts crossed.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now