473,378 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Find a record with more than 1 primary key

31
Hi All.

I am working with a form to lookup records in one of my tables. The table has 3 primary keys and is not pulling up the records correctly.

Form1 is bound to Table1 (a list of Customers and CustomerID's) ComboBox1 looks up the Customer.
Expand|Select|Wrap|Line Numbers
  1. SELECT tblCustomers.CorpID, tblCustomers.Customer 
  2. FROM tblCustomers 
  3. ORDER BY tblCustomers.Customer;
SubForm2 is bound to Table2 (list of Products by CustomerID) ListBox2 gives a list of products per customer.
Expand|Select|Wrap|Line Numbers
  1. SELECT tblCustReq.Product_ID, tblCustReq.CORP_ID, tblCustReq.ShipToID 
  2. FROM tblCustReq 
  3. WHERE Forms!ProductReq2!Customer=tblCustReq.CORP_ID ORDER BY tblCustReq.Product_ID;
The problem is when there 2 of the same ProductID's per customer then the subform will only show the record information of one of the Products no matter which one I choose.

Table2 has 3 Primary keys: CustomerID, ProductID, & ShipPoint. So the problem is when I am choosing between two products that have the same CustomerID & ProductID.

I have the form requery on current and after update. The recordset is
Expand|Select|Wrap|Line Numbers
  1. Private Sub ProductList_AfterUpdate()
  2.     ' Find the record that matches the control.
  3.  
  4.     Dim ts As Object
  5.  
  6.     Set ts = Me.Recordset.Clone
  7.     ts.FindFirst "[Product_ID] = '" & Me![ProductList] & "'"
  8.     If Not ts.EOF Then Me.Bookmark = ts.Bookmark
  9.  
  10. 'Me.Requery
  11.  
  12. End Sub
I tried
Expand|Select|Wrap|Line Numbers
  1. Private Sub ProductList_AfterUpdate()
  2.     ' Find the record that matches the control.
  3.  
  4.     Dim ts As Object
  5.  
  6.     Set ts = Me.Recordset.Clone
  7.     ts.FindFirst "[Product_ID] = '" & Me![ProductList] & "'"
  8.     ts.FindNext "[ShipToID] = '" & Me![ShipToID] & "'"
  9.     If Not ts.EOF Then Me.Bookmark = ts.Bookmark
  10.  
  11. 'Me.Requery
  12.  
  13. End Sub
but it didn't do anything.

Any help would be great.
Oct 25 '10 #1
11 2219
BarbQb
31
Is the problem really obvious and I'm just not getting it? Or does no one know how to do this?
Oct 28 '10 #2
NeoPa
32,556 Expert Mod 16PB
I expect this is because your question is so hard to understand. I knew it would be complicated when I saw the bit about multiple Primary Keys. All of us looking to answer questions know that multple PKs is not possible. Generally, a question left for three days is a strong indication that it's difficult to understand. 95% of the luck involved in getting answers, isn't luck at all, but is how the question is presented.

I was further confused when I read on because your description includes a reference to Table1, whereas the SQLs posted refer to [tblCustomers] & [tblCustReq]. I struggled on but when I got to the end I found I understood very little and wasn't in a position to offer any guidance. I'd be surprised if I were the first one to get to that point.
Oct 28 '10 #3
dsatino
393 256MB
I'll have to agree with NeoPa on that one. Your question is a bit hard to understand. Here's my best interpretation of what you problem is:

For starters, as NeoPa mentions, you can't have 3 primary keys so I'm guessing your primary key is a composite of these three fields.

As for your forms it sounds like you should have something like this:

- A form based on query that is filtered by combobox1.
- A subform that is based on a query that is filtered by combobox2. The default view of this subform should be set to continuous.

As longs as you have the correct parent/child relationships between the forms you really don't need a bunch of code.
Oct 28 '10 #4
BarbQb
31
NeoPa - Thanks for letting me know. I will be more clear next time.

dsatino - Thanks for responding. I definitely used the wrong terms when I asked my question. My primary key is 3 fields, and my form has the correct parent/child but it still is not giving me the correct record.
When I choose a Customer from ComboBox1, it filters the ProductID's in ComboBox2, which filters the subform. The problem is when there are two of the same ProductID's for one customer, I will only see the info for one of the ProductID's no matter which one I choose.
Oct 29 '10 #5
NeoPa
32,556 Expert Mod 16PB
Your lines #7 & #8 of your last attempted code do a FindFirst() then a FindNext(). This is logically not what you are looking for. You need a single FindFirst() where the criteria parameter specifies both field values you're looking for.

Something like
Expand|Select|Wrap|Line Numbers
  1.     ts.FindFirst "([Product_ID] = '" & Me.[ProductList] & "') AND " _
  2.     "([ShipToID] = '" & Me.[ShipToID] & "')"
This will find a record that matches both the [Product_ID] and the [ShipToID], rather than a record that matches the [ShipToID] and is found after the first record to match the [Product_ID].

PS. Actually you'd probably want to include the third field in the criteria too, but I don't believe we have any info on that so you'll have to do that yourself. The fundamentals are all there so it shouldn't be complicated if you have access to all the relevant information.
Oct 29 '10 #6
dsatino
393 256MB
Can you attach your db?
Nov 1 '10 #7
BarbQb
31
dsatino - Thank you for still having an interest in this. I haven't had a chance to work on the DB today, but I will post it as soon as I can.

NeoPa - Thanks for all of your help so far. I did try the code that you suggested, but it did not seem to make a difference.
Nov 2 '10 #8
NeoPa
32,556 Expert Mod 16PB
BarbQb:
NeoPa - Thanks for all of your help so far. I did try the code that you suggested, but it did not seem to make a difference.
The code was only an indicator. I don't have enough reliable information to code it for you (not that doing it for you is my wish even). I suggest you post what you actually tried and we can look to see if you've missed anything. I would not expect a simple copy-paste of my code to work for you (as explained in the post itself).
Nov 2 '10 #9
BarbQb
31
NeoPa - I will post the different variations of the code that I actually used.

The 3 fields of the Primary Key are CorpID, ProductID and ShipToID

I have attached the DB. Any comments and advice are appreciated.
Attached Files
File Type: zip db2.zip (94.6 KB, 107 views)
Nov 4 '10 #10
mshmyob
904 Expert 512MB
It could be that your table design looks wrong. The tables do not appear related to each other properly.

I would suggest reading up on normalization.

cheers,
Nov 4 '10 #11
NeoPa
32,556 Expert Mod 16PB
BarbQb:
NeoPa - I will post the different variations of the code that I actually used.
Whenever you're ready then...

I hope you don't consider an attached database as posting the code. That's just an attached database. I never even open them myself unless I've asked for, or it's not possible for some reason to continue the thread in the thread itself for some reason. I see no such reason here. Please post the code here so it can be viewed easily.
Nov 4 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bob Stearns | last post by:
I changed a varchar(255) to varchar(3000) an started receiving: Warning: odbc_exec(): SQL error: SQL1585N A system temporary table space with sufficient page size does not exist. SQLSTATE=54048...
3
by: Sarah Smith via AccessMonster.com | last post by:
I am creating a database of documents that need to be worked on, are int eh proress of being worked on, and have been completed. Sometimes the same document (an updated version) comes back for more...
3
by: Randy | last post by:
I have been able to set up a Find Record Button on my switchboard to take me to a form with the correct case number by using a parameter query and macro. When I try to run the Find Record button...
0
by: AA Arens | last post by:
I made a find record button on my form "company" (with field for name, phone nr, e-mail etc.). I expect that when I focus on one of the field, the "look in" of the find-record dialog box should...
7
by: gjoneshtfc | last post by:
Hello I want to search my database for a vehicle registration number but before i can search using the Find Record button i created i have to click in the registration field so that it is that...
1
by: crazdandconfusd | last post by:
I created a form based on one table and was able to find information using find record and searching entire form. Now I split the information into two tables: one for the front of a page to be...
3
by: betterdayz | last post by:
hi...im trying to design the "find record" command whereby the user enters an ID Number and than clicks ok and the database does a search for that particular ID...the wizard command uses find and...
1
by: farhan31 | last post by:
Hello all I have Two tables.Table 1 and table 2.Table 1 has one to many relation with Table 2.I have one main form Form1 based on table 1.On form 1 i have a sub form based on table 2.I have put a...
1
Run2Eat
by: Run2Eat | last post by:
i feel like this is a doofus question... but i've created an access form and added a find record button, but when i use the form, the find record button searches the form itself, not the table. all...
1
by: =?Utf-8?B?Rm9lZg==?= | last post by:
I have a BindingSource with an underlying table with two primary keys. To set the position with one primary key works fine as shown in the code snippet below: Dim index As Integer =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.