Results 1 to 15 of 15
  1. #1
    sharonir22 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    16

    Multi field criteria

    Hi

    I have a table that has location coordinates in 2 different fields - X and Y.

    I have built a function called Distance which accepts 2 location's data (4 variables) and returns the distance between them.

    I would like to design a query that will be called from a form that shows all the records in which the distance between them and the form entered location is smaller than 5.



    The problem is i don't know how to set a criteria using 2 fields.

    HELP

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Sounds like you can call the function from the query, passing 2 variables from the data and 2 from the form, and put a criteria on that field.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What two fields? You have only one parameter - distance. How do you calculate distance between locations in table? Show sample data. I think what you want will be complicated. This is handled by complex algorithms in specialty applications like ESRI ArcGIS mapping and Google Earth. Replicating this in Access will probably require a query that self-joins the table so every location is associated with every other location (Cartesian relationship) then calculate distance for each of these pairings and apply distance parameter to that field.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    sharonir22 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    16
    A location is defined by 2 parmeters. X as horizontal location and Y as diagonal location. Both numbers with 6 digits. the function uses pythagorean theorem to calculate the distance between them.

  5. #5
    sharonir22 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    16
    I have a form used to enter a location (x and y) and I want a query that returns all the records that are in a 5 meter radius of it.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I edited my previous reply as you were reading. Review again.

    Wait, I misread the OP. I think Paul has it right.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    sharonir22 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    16
    If I have a field in which the location data is stored as xxxxxx/yyyyyy is there a way to seperate the x and the y just to use the function?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I thought you said the x and y are in different fields - they should be.

    String manipulation functions can parse the data.


    In query:

    For the x: Val([field name])
    or Left([field name], 6)
    or Left([field name], InStr([field name], "/")-1)

    For the y: Mid([field name], InStr([field name], "/")+1)
    or Mid([field name], 8)
    or Right([field name], 6)
    or Right([field name], InStrRev([field name], "/")-1)

    In VBA can use Split() and an array variable.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You can use the Split() function, or if the values are always 6 digits you can use the Left() and Right() functions.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    sharonir22 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    16
    Just to update, i converted my 2 fields into 1 and used the string functions as suggested. My query now works pefectly and i'm very pleased

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I am confused. I thought you said the data was already 1 field? X and Y should be in separate fields.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    sharonir22 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    16
    It was in 2 fields.now its much easier

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I would never put x and y values into one field. I would figure out what needs to be modified in function.

    However, if you are satisfied with resolution, I guess that's what counts.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    FWIW, I'd have kept them separate too. It's always easier to join multiple fields together as needed than to split one apart.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The exception being date/time data. Because of the multitude of date/time functions for extraction of parts, better to have one field for date/time than separate fields for month, day, year, hour, minute, second or to even split date from time. Keep date/time as one field. However, dealing with date/time ranges that cross midnight can be frustrating regardless of how saved. Midnight is saved without time part, just the date.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 12-10-2013, 11:30 PM
  2. How do I return a value on multi criteria?
    By smc678 in forum Access
    Replies: 5
    Last Post: 11-20-2012, 02:35 PM
  3. Replies: 5
    Last Post: 08-02-2012, 09:44 AM
  4. Multi Criteria Searchform
    By cap.zadi in forum Queries
    Replies: 31
    Last Post: 01-20-2012, 01:56 PM
  5. Multi Criteria Query
    By hawkins in forum Queries
    Replies: 1
    Last Post: 07-18-2011, 01:44 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