Solved

Differentiating names form and subform

Posted on 2015-02-16
5
163 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

863 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

22 Experts available now in Live!

Get 1:1 Help Now