Results 1 to 11 of 11
  1. #1
    pjordan@drcog.org is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2011
    Location
    Denver, CO
    Posts
    71

    Using FindRecord to jump to Specific Records with Criteria

    Did some research and am not able to understand how to accomplish this (I am sure it's pretty simple).

    I have a form (called MASTER_FORM) and its just a simple form that has Location data (address, County, Longitude and Latitude, etc).

    The records all have the location and County and City imported in by another database, but we need to populate the exact LONG and LAT for these locations. So as time goes by, the database is filled with records that have LONGITUDE and LATITUDE populated. My question is I want to make a simple search button (assume using the DoCmd.FindRecord where the LONGITUDE is Null. That way the user can easily open the database, and on the Form just press that button to go to the next record that needs to be updated.



    I've been playing around with the syntax and keep getting "Compile Error: Argument not optional"

    Here's what I'm using (I am keeping the defaults in so I know I have the right number of variables). However I feel NULL shouldn't be in quotes, but I can't seem to get it to work either way.


    DoCmd.FindRecord , LONGITUDE="Null", acEntire, False, acSearchAll, False, acCurrent, True

    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Dont use FINDRECORD, instead FILTER the records by using a continuous form to show all records,
    then when the user fills in the boxes, then clicks the FIND button, use vb to build the where clause:

    Code:
    sub btnFind_click()
    dim sWhere as string
    
    if not IsNull(txtBox1) then sWhere = sWhere & " and [field1]='" & me.txtBox1 & "'"
    if not IsNull(txtBox2) then sWhere = sWhere & " and [field2]='" & me.txtBox2 & "'"
    if not IsNull(txtBox3) then sWhere = sWhere & " and [field3]='" & me.txtBox3 & "'"
    
    if sWhere = "" then
       me.filterOn = false
    else
        sWhere = mid(sWhere,5)       'remove the 1st 'and'
       me.filter = sWhere
       me.filterOn = true
    endif
    end sub

  3. #3
    pjordan@drcog.org is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2011
    Location
    Denver, CO
    Posts
    71
    Ok so how do I do this when the field LONGITUDE is a Double Number and not actually a Text? Since I keep getting the Data Mismatch Error​? Oh and the TXT_Long, the TXT part refers to the type of object in the FORM not that it's actually a text field...

    Thanks.

    Code:
    Dim sWhere As String
    
    
    If Not IsNull(TXT_Long) Then sWhere = sWhere & " and [LONGITUDE]='" & Me.TXT_Long & "'"
    
    
    If sWhere = "" Then
       Me.FilterOn = False
    Else
        sWhere = Mid(sWhere, 5)      'remove the 1st 'and'
       Me.Filter = sWhere
       Me.FilterOn = True
    End If
    
    
    Exit_BTN_BlankLoc_Click:
        Exit Sub
    
    
    Err_BTN_BlankLoc_Click:
        MsgBox Err.Description
        Resume Exit_BTN_BlankLoc_Click
        
    End Sub

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Use quotes for text fields, no quotes for number fields, # for date fields.

    Test it by creating a new query and adding it as a criteria. Look at the SQL view and it will show you the exact format to use for your filter.

  5. #5
    pjordan@drcog.org is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2011
    Location
    Denver, CO
    Posts
    71
    Quote Originally Posted by aytee111 View Post
    Use quotes for text fields, no quotes for number fields, # for date fields.

    Test it by creating a new query and adding it as a criteria. Look at the SQL view and it will show you the exact format to use for your filter.
    Yes I was trying to remove the quotes and it doesn't work. Tried various options as I knew they have to be removed somehow, just not sure how. Plus it won't work in SQL from a new Query as it says the functions are supported in this version (using Office 365)...

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    and [LONGITUDE]=" & Me.TXT_Long
    This doesn't work in 365?

  7. #7
    pjordan@drcog.org is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Dec 2011
    Location
    Denver, CO
    Posts
    71
    Well my mistake was I used a different code by accident. However trying to just use If Not IsNull(TXT_Long) Then sWhere = sWhere & " and [LONGITUDE]='" & Me.TXT_Long & "'" doesn't get me anywhere because of the ' that are in the script above. Not much of a programmer here...

  8. #8
    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,870
    pjordan,

    Do you have lat/Long coordinates for specific street addresses or just for city?
    I found a file on internet ~ 40,000 records that shows

    zipcode
    city
    state
    Lat/long

    But it doesn't show individual homes/businesses.

    If you have access to the table with the Lat/Long and the table you are populating, why can't you use a query with both tables with a JOIN on the common unique field?

    If I have misunderstood your requirement/issue, perhaps you could provide more details and clarification.

    Good luck.

  9. #9
    pjordan@drcog.org is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Dec 2011
    Location
    Denver, CO
    Posts
    71
    Quote Originally Posted by orange View Post
    pjordan,

    Do you have lat/Long coordinates for specific street addresses or just for city?
    I found a file on internet ~ 40,000 records that shows

    zipcode
    city
    state
    Lat/long

    But it doesn't show individual homes/businesses.

    If you have access to the table with the Lat/Long and the table you are populating, why can't you use a query with both tables with a JOIN on the common unique field?

    If I have misunderstood your requirement/issue, perhaps you could provide more details and clarification.

    Good luck.
    The addresses we have are crashes done by the police, so often they give the house address. These locations using various geocoding never seem to accurately get coded properly (only intersections geocode correctly). So with these ones in this database we are building our own database. We used to have other options, but the prices of geocoding and the results haven't been that great. The big issue is the Zip Codes are not included and seems most if not all geocoding services now use that for better accuracy.

    So currently to get to the next record with a missing value I just do a Find and Replace and search in the Longitude box for finding "is Null". But was just wanting a simple button to do that instead (as sometimes people might forget how to search for a null in the Find and Replace box. That was all.

    I was thinking it would be a simple thing, but seems it's not as straight forward as I was hoping.

    I even tried something like this without success:
    Code:
    If IsNull(TXT_Long) = False Then      Me.Recordset.FindFirst "[LONGITUDE]=" & ""
          If Me.Recordset.NoMatch Then
             MsgBox "All LAT/LONG are Populated", vbOKOnly + vbInformation, "NO MORE RECORDS NEED TO BE UPDATED"
          End If
    I could just have a query to find all the records that have a blank LONGITUDE and then sort it and just use TOP 1 I guess. But was just hoping there was a quicker way. Hope that clarifies things...

  10. #10
    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,870
    If you have addresses, you can get lat/long from Google Maps. There is a limit of about 2500 searches/lookups per day, but that doesn't seem to be an issue in your case.

  11. #11
    pjordan@drcog.org is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Dec 2011
    Location
    Denver, CO
    Posts
    71
    No and if you use the Google API like we tried out for geocoding, it actually gives inaccurate locations for many of the addresses without a Zip Code. Manually putting the address in Google however works. This has been the issue with using Google, ESRI, and a load of other goecoding sources.

    I just made a simple Query to do the Top 1 for Null LONGITUDE and then the user can just copy the ObjectID and use the Search ObjectID button (or Find/Replace) for that number and quickly jump to it. I was just thinking there had to be an easier way in the Form to do this, but seems not...

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

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2016, 12:15 PM
  2. Replies: 6
    Last Post: 07-27-2015, 10:23 AM
  3. Replies: 11
    Last Post: 05-19-2015, 08:35 AM
  4. Replies: 4
    Last Post: 08-30-2014, 10:23 AM
  5. FindRecord Crash if criteria not found
    By quicova in forum Programming
    Replies: 4
    Last Post: 09-13-2013, 08:42 AM

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