Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Developers    Comments List
Upload Images | @Reply | Bookmark | Link | Email | Next Unseen |
I gave up am asking for help
Sandra Truax 
         
3 years ago
I give up. I've been trying to figure this out for nearly two weeks, and I've gone from this almost working code to crashing the database over and over.  If someone could help me I would be forever thankful!

Here's what I've got and what I am trying to do.

I have a table called DirectoryT which contains a DirectoryId Autonumber Primary field, and Text field Directory Name.

I have a Many-to-Many Table (MasterDirectoryT), with a MasterID (Primary field), ParentID linked back to DirectoryT, ChildID linked back to DirectoryT, and a text field FullDirectoryName.

I have a DirectoryQ query that pull it all together (MasterID, ParentID, ChildID, DirectoryName, FullDirectoryName)

The DirectoryT has just the DirectoryName (e.g. Photos, Videos, 2020, 2021)
I was trying to eliminate having to make records such as D:\Photos\2020\, and then duplicating the year for the videos

My code works like I want, until it hits the example above, and there is not telling what kind of crap I get. And since I use the years in multiple other directories, this has made my work all for nothing.

ParentID  ChildID  FullDirectoryName
3  8   D:\01\From HP computer\
137  8   D:\01\From HP computer\

As long as I don't have a DirectoryName I've used before, it works fine.

So now that I've probably bored you to sleep.  Here is my code. If you can help me fix it so that the entries with duplicate years populate right I'll dance a dance of joy!


Code
Private Sub GenerateNameBtn_Click()
    PopulateNameField
End Sub

Sub PopulateNameField()
    If IsNull(DirectoryName) Then Exit Sub
    Dim TargetDirectoryID As Long
    TargetDirectoryID = ChildID ' Replace this with the ID of the directory you want to process
    GenerateFullDirName TargetDirectoryID
    Me.FullDirectoryName = FullDirectoryName ' Update the FullDirectoryName field in the current record
    Me.Refresh
End Sub

Private Sub GenerateFullDirName(ByVal DirectoryID As Long)
    Dim DirectoryName As String
    On Error Resume Next

    ' Replace "DirectoryQ" with the actual name of your query (e.g., "DirectoryQ").
    DirectoryName = DLookup("DirectoryName", "DirectoryQ", "ChildID=" & DirectoryID)

    If IsNull(DirectoryName) Or DirectoryName = "" Then
        FullDirectoryName = ""
    Else
        Dim ParentID As Long
        ParentID = DLookup("ParentID", "DirectoryQ", "ChildID=" & DirectoryID)

        If IsNull(ParentID) Then
            FullDirectoryName = DirectoryName & "\"
        Else
            GenerateFullDirName ParentID ' Recursive call to get the parent directory name
            FullDirectoryName = FullDirectoryName & DirectoryName & "\"
        End If
    End If

    On Error GoTo 0
End Sub
Kevin Yip  @Reply  
     
3 years ago
Hi Sandra, I'm not sure why you have such an elaborate way to recreate folder paths.  If you're doing this because your files keep changing locations, consider storing their "relative locations" in your table, and put the "absolute location" in another table.  For instance:

Table1:
AbsolutePath
C:\Documents

Table2:
FileID     RelativePath
1     Myfolder\Filename1
2     Myfolder\Filename2
3     Myfolder\Filename3
4     Myfolder\Filename4
5     Myfolder\Filename5
...

In this case, when the files are moved from, say, C:\Documents\Myfolder to D:\SomewhereElse\Myfolder, you only need to change the entry in Table1, and doesn't have to change anything in Table2.  I always store my file paths that way, in anticipation of any possible relocations.
Sandra Truax OP  @Reply  
         
3 years ago
Thanks Kevin. I am going to delete what I did and am going with your suggestion.  I had something similar to this, but wanted to build my index by being able to start at D:\ and go down the list and with the folders in that file and it automatically generate the MyFolder for me since I have so many, and asked ChagGPT for help, and wa la... lots of wasted hours. My brain is exhausted!  Thanks for your input. Very helpful, as usual.
Kevin Yip  @Reply  
     
3 years ago
ChatGPT is far from the perfect in terms of code generation.  I asked it to generate a list of randomly-generated mailing addresses, and it couldn't even do that satisfactorily.  Auto-coding is not a new thing; it's at least decades old.  Many web tools can create "templates" of automatically generated HTML codes with ease, and with precise and exact results.  And that's the main problem with ChatGPT: it uses "fuzzy logic" that is far from precise and exact.  With coding, you have to have precision and accuracy.  

But having said that, AI will eventually be able to do this with much better precision in, I would say, the next 5 years or less.  That's because with tons of data and power, even "fuzzy logic" can become precise.  That was how handwriting recognition became reality.  We used to think that, if we humans couldn't even recognize someone else's handwriting, how could a machine?  But what a machine could do was looking at gazillion people's handwritings.  Some people would write the letter "l" as a vertical line, as a loop, slanted right, slanted left, etc.  If AI looked at tons of samples like these, it WOULD be able to recognize the letter "l" with great accuracy, no matter how it was written.  The same thing will be true for recognizing program code.
Sandra Truax OP  @Reply  
         
3 years ago
In a way it is kinda scary, AI getting so intellegent, but I like it!  They very interesting info about the handwriting recognition. I hadn't ever heard of that.  Thanks for sharing.
Scott Axton  @Reply  
      
3 years ago
Did you watch the Terminator?  

It all starts innocently then...
Sandra Truax OP  @Reply  
         
3 years ago
Yes Scott, I have watched the Terminator, and it is definitely something to worry about. Between AI people and aliens, I worry what this world is going to be like when my grandsons are my age!

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developers.
 

Next Unseen

 
 
What's This?

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 10/31/2026 6:17:39 PM. PLT: 0s