Solved

Differentiating names form and subform

Posted on 2015-02-16
5
164 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: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 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:Simon
ID: 40613087
No problem. I may have edited it since you saw it. I think our posts crossed.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

810 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