UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Dcount, Access 2010    
 
   
Pastor Del
post Feb 17 2019, 03:32 PM
Post#1



Posts: 335
Joined: 27-July 10



How can I use the DCount method to verify a certain record exists when part of the criteria depends on data from a linked table? If there was only 1 table involved the following code would work but the serial number is linked to a circuit board number in a different table.

CODE
txtSN = TSI001

If DCount("SN", "tblSN","SN = txtSN") > 0 Then
   Do something
End If


Here is the relationship

Attached File  Relationship.png ( 4.99K )Number of downloads: 1
Go to the top of the page
 
isladogs
post Feb 17 2019, 03:40 PM
Post#2


UtterAccess VIP
Posts: 1,707
Joined: 4-June 18
From: Somerset, UK


I must be missing the point here but SN is in the table tblSN so why won't it work?
Referential integrity has been applied but I don't see why the other table is relevant unless you also need to filter for the PWA field.

If that is necessary do an aggregate query to get the count filtering on the relevant field(s)

--------------------
Go to the top of the page
 
theDBguy
post Feb 17 2019, 03:56 PM
Post#3


Access Wiki and Forums Moderator
Posts: 76,425
Joined: 19-June 07
From: SunnySandyEggo


Hi. Are you saying the SN field is a foreign key? If so, you can use DLookup() in conjunction with your DCoun(). For example,

CODE
DCount("*","tblSN","SN=" & DLookup("ID","Circuitboards","SN='" & txtSN & "'"))


Sent from phone...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
Pastor Del
post Feb 18 2019, 12:46 AM
Post#4



Posts: 335
Joined: 27-July 10



Thanks, I'll give it a try.
Go to the top of the page
 
Pastor Del
post Feb 18 2019, 02:02 AM
Post#5



Posts: 335
Joined: 27-July 10



Thanks again. I got it. It's been a while since I've done any serious programming so I'm a little rusty but it will come back
Go to the top of the page
 
theDBguy
post Feb 18 2019, 12:50 PM
Post#6


Access Wiki and Forums Moderator
Posts: 76,425
Joined: 19-June 07
From: SunnySandyEggo


Hi. Congratulations! Glad to hear you got it to work. Good luck with your project.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    22nd October 2019 - 09:36 PM