Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    SaraM is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    14

    I need to use two criteria's before linking two tables in a third table

    I've two tables, the first one is tblObject, which contains around 5000~ buildings spread out over Paris and I've tblFiles, which contains pictures and reports about these buildings, we are speaking about roughly 143,000 files.

    tblObject and tblFiles need to be linked together and inserted into in a third table, tblObjectFile, if there is a match. So for example, the Eifel Tower has the same Objectnumber "NB0001", and if there is a tblFile with "NB0001" or "0001" in it, it will automatically link them.

    The problem is that now it will link automatically any file to the object as long as he finds the Objectnumber, and this causes mistakes as sometimes they don't belong together. Here's an example of what I mean:

    This is correct, tblObject has found an exact match with the tblFile in \Rapporten\1981\1981_0001.pdfClick image for larger version. 

Name:	escara.PNG 
Views:	13 
Size:	2.8 KB 
ID:	33247

    And this is wrong, as "0001" is just part of the name name.

    Click image for larger version. 

Name:	wrong.PNG 
Views:	13 
Size:	3.3 KB 
ID:	33248


    How can I make sure this does not happen while linking tblObject with tblFile?


    A first criteria would be that for files in certain maps, like \\rapporten, it could use the standard code as the design is just year_month_ObjectNumber.pdf (see the first picture)
    While in other directories, like \\Horst, it would have to find an exact match before linking to prevent bad links (see the last picture)

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    not following your requirement. If your first table contains

    PS0001
    NB0001

    and you search for 0001 (presumably using criteria Like *0001*) of a table that contains a record with a value that contains 0001, then it will be returned to both records in the first table.

    provide some clearer examples and define the rule required more clearly. For example if it is the case the search should only be searching the last say 10 characters of the target string, use the right function to only search that bit. Or perhaps it is the bit after the last underscore?

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    You have 3 choices
    1. Rename all files so the naming convention is consistent e.g. 0001 followed by a .
    You can get batch rename utilities for free
    2. Devise a pattern that works for all files
    3. Devise a pattern that works for each file type then use Select Case code based on file type
    Do whichever is easiest though perhaps 1 will be best in the long run
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    SaraM is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    14
    Quote Originally Posted by Ajax View Post
    not following your requirement. If your first table contains

    PS0001
    NB0001

    and you search for 0001 (presumably using criteria Like *0001*) of a table that contains a record with a value that contains 0001, then it will be returned to both records in the first table.

    provide some clearer examples and define the rule required more clearly. For example if it is the case the search should only be searching the last say 10 characters of the target string, use the right function to only search that bit. Or perhaps it is the bit after the last underscore?
    I edited my post, all the objects start with NB followed by the objectnumber, maybe this clarifies it a bit

    This is a screenshot of tblObject

    Click image for larger version. 

Name:	objectnummer.PNG 
Views:	14 
Size:	15.0 KB 
ID:	33252


    As you can see, they all have the same structure
    -------------------------------------------------------------
    This is an example of tblFile
    Click image for larger version. 

Name:	fldFile.png 
Views:	14 
Size:	42.8 KB 
ID:	33253

    As you can see, there is also consistency in some directories, where the 4 digits are behind the year. This is ok, but you have some directories where there is no consistency and the numbers are part of the naming, and where I need to use an exact match, like in the following example:
    Click image for larger version. 

Name:	fldfile2.png 
Views:	14 
Size:	43.7 KB 
ID:	33254


    The first record, 0400801 will be linked to tblObject NB0801 and that is not the point of it, so for files like in \schots, I need to have an exact match to correctly link it

  5. #5
    SaraM is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    14
    Quote Originally Posted by ridders52 View Post
    You have 3 choices
    1. Rename all files so the naming convention is consistent e.g. 0001 followed by a .
    You can get batch rename utilities for free
    2. Devise a pattern that works for all files
    3. Devise a pattern that works for each file type then use Select Case code based on file type
    Do whichever is easiest though perhaps 1 will be best in the long run
    I cannot rename them, all the files are on the company server and I only have read permission...

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    This is a screenshot
    none of your attachments are valid and cannot be opened

    Providing a single example for string searches ie often insufficient (as in this case).

    To make the search more focused you need to be able to apply some rules - for example as I suggested, always in the last 10 chars, or after the last _. or it may be that the preceding value should not be a zero. It could be anything- what if it matches something in the bit you have blacked out?

    From your example the two suggestions I made would work, but no idea if that is sufficient for your needs or whether you know how to apply them

    Can't help further without more information except by guessing what it is you require

  7. #7
    SaraM is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    14
    Quote Originally Posted by Ajax View Post
    none of your attachments are valid and cannot be opened

    Providing a single example for string searches ie often insufficient (as in this case).

    To make the search more focused you need to be able to apply some rules - for example as I suggested, always in the last 10 chars, or after the last _. or it may be that the preceding value should not be a zero. It could be anything- what if it matches something in the bit you have blacked out?

    From your example the two suggestions I made would work, but no idea if that is sufficient for your needs or whether you know how to apply them

    Can't help further without more information except by guessing what it is you require
    I updated the pictures, maybe you can see them now? And I've no idea how to apply them, is it with a "If Instr" statement?

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    OK, but you still have not made clear what constitutes a correct 'match'. All you are providing is what it does not match

  9. #9
    SaraM is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    14
    Quote Originally Posted by Ajax View Post
    OK, but you still have not made clear what constitutes a correct 'match'. All you are providing is what it does not match
    A correct match is when the four digits are the same, so when the Object is lets say "NB0001", I've put in my query that for tblFile, the criteria is Like *0001*
    It matches a lot of them correct for sure, but it also accidentally matches sometimes, where those four digits are part of the name in tblFile, for example 0480001 would be matched with object NB0001

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    sorry, you are still not answering my questions.

    can a valid match be in any part of the target string? are there any identifying characters around the string such as preceded by an underscore or occurs as part of the file name

    If you can't answer these questions, I can't help you

  11. #11
    SaraM is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    14
    Quote Originally Posted by Ajax View Post
    sorry, you are still not answering my questions.

    can a valid match be in any part of the target string? are there any identifying characters around the string such as preceded by an underscore or occurs as part of the file name

    If you can't answer these questions, I can't help you
    Yes, it can be part of any part of the target string and yes, most are preceded by an underscore

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Sara,

    It seems you are looking for an algorithm/method (singular) to do the matching. But it is your "most" (read that to include -many, very often, almost all....) that suggests there is no single method for this.

    If there are other rules to match specific patterns, then perhaps there is a need for a small number of algorithms to do the matching. One algorithm for each identified pattern.

  13. #13
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    to capture the ones preceded by an underscore use

    like "*_" & mid([objectnummer],3) & "*"

    agree with Orange, but you aren't providing any data for us to help you with that

  14. #14
    SaraM is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    14
    Quote Originally Posted by orange View Post
    Sara,

    It seems you are looking for an algorithm/method (singular) to do the matching. But it is your "most" (read that to include -many, very often, almost all....) that suggests there is no single method for this.

    If there are other rules to match specific patterns, then perhaps there is a need for a small number of algorithms to do the matching. One algorithm for each identified pattern.
    Quote Originally Posted by Ajax View Post
    to capture the ones preceded by an underscore use

    like "*_" & mid([objectnummer],3) & "*"

    agree with Orange, but you aren't providing any data for us to help you with that
    I sent you guys a message with my data

  15. #15
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Please be explicit--what does this mean?

    This is the file itself, the linking button is located in "cmdKoppelPaul", tblbestanden = tblfile

    I also note that there are no relationships in your database.
    This is the caption for cmdKoppelPaul Koppel alle bestanden

    I'm looking/reviewing at the click event
    Code:
    Private Sub cmdKoppelPaul_Click()
    Dim vDB As DAO.Database
    Dim vRST As DAO.Recordset
    Dim strSQLObject As String
    Dim strSQLBestand As String
    Set vDB = CurrentDb
    strSQLObject = "SELECT * from tblobjecten order by objectnummer"
    Set vRST = vDB.OpenRecordset(strSQLObject, dbOpenDynaset, dbSeeChanges)
    vRST.MoveFirst
    Do While Not vRST.EOF
        strSQLBestand = "INSERT INTO tblobjectbestand (fldobjectid,fldbestandid)VALUES (1068, 688999)"
        strSQLBestand = strSQLBestand & " SELECT " & vRST!objectid & ", fldbestandid FROM tblbestand where instr(fldbestand," & Chr(34) & vRST!Objectnummer & Chr(34) & ") >0"
        'DoCmd.SetWarnings False
        'DoCmd.RunSQL strSQLBestand
        Debug.Print strSQLBestand
        'CurrentDb.Execute strSQLBestand, dbFailOnError
        vRST.MoveNext
    Loop
    End Sub
    I tried using the debug.print output as a query to see if it would be accepted by Access.
    Code:
    INSERT INTO tblobjectbestand (fldobjectid,fldbestandid)VALUES (1068, 688999) SELECT 1068, fldbestandid FROM tblbestand where instr(fldbestand,"NB0001") >0
    It fails saying no semicolon at the end, but I don't believe that's an issue(yet).

    You would not need a VALUES and Select in the same query sql???
    I am confused on what exactly is your intent with this code??????????????

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Lookup Tables - how to use without linking in table design
    By grapevine in forum Database Design
    Replies: 15
    Last Post: 08-29-2017, 01:50 PM
  2. Replies: 4
    Last Post: 07-08-2014, 08:59 AM
  3. Replies: 6
    Last Post: 05-16-2012, 12:43 PM
  4. Linking tables to show primary key from main table
    By Mark_435 in forum Database Design
    Replies: 5
    Last Post: 01-12-2012, 09:20 PM
  5. Linking a student table to multiple tables
    By iteachyou in forum Access
    Replies: 3
    Last Post: 02-06-2011, 05:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums