Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: DLookup: One to many table relationships

Started 1 month, 2 weeks ago by Rick Stanich
I am having trouble with syntax for a DLookup. Code: Private Sub tbJobNo_BeforeUpdate(Cancel As Integer) 'Get the Pk value of the Job number in tblJobs lngID = DLookup("pkJobID", "tblJobs", "txtJobNo='" _ & Me.tbJobNo & "'") 'Now check if the revision value entered exists for that _ Job numbers PK value in tblJobs If IsNull(DLookup("txtJobNo", "tblJobs", "txtJobNo='" _ ...
Site: Access World Forums  Access World Forums - site profile
Forum: Forms  Forms - forum profile
Total authors: 3 authors
Total thread posts: 17 posts
Thread activity: no new posts during last week
Domain info for: access-programmers.co.uk

Other posts in this thread:

boblarson replied 1 month, 2 weeks ago
Rick: I'm still kind of trying to figure out exactly what you are saying for your DLookup part, but I'm wondering if your tables/relationships are proper. I usually find if the relationships seem to form a circle then something is not right.

Rick Stanich replied 1 month, 2 weeks ago
Better example? In this code I set a value for tbPartNo based on tblParts. Code: Private Sub tbPartNo_BeforeUpdate(Cancel As Integer) 'This code revision thanks to Beetle of MS Access Groups) 'Lookup the value in the table using Dlookup. 'Dlookup will return Null if the value is not found so 'we check for that using the IsNull function. If IsNull(DLookup("txtPartNo", "tblParts", "...

namliam replied 1 month, 2 weeks ago
Why do two DLookups, when you can do this in one simple query?? Code: lngID = DLookup("pkPartID", "tblParts", "txtPartNo='" _ & Me.tbPartNo & "'") 'Now check if the revision value entered exists for that 'part numbers PK value in tblPartRev If IsNull(DLookup("txtRev", "tblPartRev", "txtRev='" _ & Me.tbRev & "' And fkPartID=" & lngID)) Then D...anything is to be ...

boblarson replied 1 month, 2 weeks ago
I would use DCount instead in this situation where you just want to know if it exists. So, something like: Code: If DCount("txtPartNo", "tblParts", "txtPartNo='" _ & Me.tbPartNo & "'") = 0 Then And Code: If DCount("txtRev", "tblPartRev", "txtRev='" _ & Me.tbRev & "' And fkPartID=" & lngID) = 0

Rick Stanich replied 1 month, 2 weeks ago
namliam I have two textboxes so I thought, hey, two DLookups. One for each textbox. boblarson I originally had DCounts, I was redirected, at this stage I do not know which methods are best until people such as yourself or namliam tell me different, none the less they are both excersizes in Access that help me understand some things. Which is the point of all my post and questions, I am ...

boblarson replied 1 month, 2 weeks ago
Quote: Originally Posted by Rick Stanich boblarson I originally had DCounts, I was redirected, at this stage I do not know which methods are best until people such as yourself or namliam tell me different, none the less they are both excersizes in Access that help me understand some things. Which is the point of all my post and...

Rick Stanich replied 1 month, 2 weeks ago
Using your last suggestion appears to work when a user enters a value that "is" in the table holding "fkPartID". If I type any value like "x" (just an example) that isnt in the table I get an error: Quote: Run-time error '94': Invalid use of null

boblarson replied 1 month, 2 weeks ago
Quote: Originally Posted by Rick Stanich Using your last suggestion appears to work when a user enters a value that "is" in the table holding "fkPartID". If I type any value like "x" (just an example) that isnt in the table I get an error: What does it highlight?

Rick Stanich replied 1 month, 2 weeks ago
The error highlites this segment of code in its entirety. Only if a value is entered that is not in a table. Code: lngID = DLookup("pkJobID", "tblJobs", "txtJobNo='" _ & Me.tbJobNo & "'")

boblarson replied 1 month, 2 weeks ago
Change this: Code: lngID = DLookup("pkJobID", "tblJobs", "txtJobNo='" _ & Me.tbJobNo & "'") to this: Code: lngID = Nz( DLookup("pkJobID", "tblJobs", "txtJobNo='" _ & Me.tbJobNo & "'") ,0)

 

Top contributing authors

Name
Posts
Rick Stanich
8
user's latest post:
DLookup: One to many table...
Published (2009-11-09 12:34:00)
Thats funny, and scary at the same time. LOL
boblarson
8
user's latest post:
DLookup: One to many table...
Published (2009-11-09 12:35:00)
Quote: Originally Posted by Rick Stanich Thats funny, and scary at the same time. LOL It's how I get to look by the end of the day at work
namliam
1
user's latest post:
DLookup: One to many table...
Published (2009-11-09 08:13:00)
Why do two DLookups, when you can do this in one simple query?? Code: lngID = DLookup("pkPartID", "tblParts", "txtPartNo='" _ & Me.tbPartNo & "'") 'Now check if the revision value entered exists for that 'part numbers PK value in tblPartRev If IsNull(DLookup("txtRev", "tblPartRev",...

Related threads on "Access World Forums":

Related threads on other sites:

Thread profile page for "DLookup: One to many table relationships" on http://www.access-programmers.co.uk. This report page is a snippet summary view from a single thread "DLookup: One to many table relationships", located on the Message Board at http://www.access-programmers.co.uk. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity