Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    nvrwrkn is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2012
    Posts
    35

    Form data in SELECT statement recordset

    Getting the Expected 3 runtime error from the following and I believe it has to do with how I'm using the form data, I've read that form data isn't available to recordset.

    Code:
    Public Function GetLoc()
    Dim GeoData As DAO.Database
    Dim Location As DAO.Recordset
    Set GeoData = CurrentDb
    Set Location = GeoData.OpenRecordset("SELECT TOP 1 CStr(CInt(GeoData!Area))+GeoData!Block+GeoData!Space " & _
            "FROM GeoData " & _
            "WHERE (((GeoData.EVEN_ODD_I)=IIf(Right([Forms]![Activity]![StreetNo],1)=0,'E',IIf(Right([Forms]![Activity]![StreetNo],1)=2,'E',IIf(Right([Forms]![Activity]![StreetNo],1)=4,'E',IIf(Right([Forms]![Activity]![StreetNo],1)=6,'E',IIf(Right([Forms]![Activity]![StreetNo],1)=8,'E','O')))))) And ((GeoData!STREET_DIRECTION_CD)=[Forms]![Activity]![StreetDir]) And ((GeoData!STREET_NME) Like [Forms]![Activity]![StreetName]+'*') And (([Forms]![Activity]![StreetNo]) Between GeoData!LOW_ADDRESS_NO And GeoData!HIGH_ADDRESS_NO)) ")
       
    Debug.Print Location
    
            
    End Function
    GeoData is a linked table. Form is open and data is inside references, above works in a query, I copied it directly from the query.



    I read something about putting the form references outside quotes but I'm not seeing how to do that, tried it a few ways and nothing worked.

  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,642
    Well, this type of thing:


    "...IIf(Right(" & [Forms]![Activity]![StreetNo] & ",1)=0..."

    But you don't need all that to determine even/odd, you can do it with the Mod function:

    "Any Even Number" Mod 2 = 0
    "Any Odd Number" Mod 2 = 1
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    nvrwrkn is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2012
    Posts
    35
    thanks for the MOD reminder ;/ always forget that one.

    Now I'm getting method of object forms error.

    Code:
    Public Function GetLoc()
    Dim GeoData As DAO.Database
    Dim Location As DAO.Recordset
    Set GeoData = CurrentDb
    Set Location = GeoData.OpenRecordset("SELECT TOP 1 CStr(CInt(GeoData!Area))+GeoData!Block+GeoData!Space " & _
            "FROM GeoData " & _
            "WHERE (((GeoData.EVEN_ODD_I)=IIf(" &  [Forms]![Activity]![StreetNo] & " MOD 2 = 0,'E','O')) And  ((GeoData!STREET_DIRECTION_CD)=" & [Forms]![Activity]![StreetNo]  & ") And ((GeoData!STREET_NME) Like " &  [Forms]![Activity]![StreetNo] & "+'*') And ((" &  [Forms]![Activity]![StreetNo] & ") Between GeoData!LOW_ADDRESS_NO  And GeoData!HIGH_ADDRESS_NO)) ")
       Debug.Print Location
    Form is open, correct data available.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Use a variable for the SQL and this technique will make it easier to find the problem:

    http://www.baldyweb.com/ImmediateWindow.htm

    Is StreetNo a text field in the table?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    nvrwrkn is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2012
    Posts
    35
    I'll give that a try, I used the debug recommendation from that link earlier.

    StreetNo is a text field on the form, it's used between the two table fields HIGH_ADDRESS & LOW_ADDRESS which are number fields. The table is a GIS table where areas are mapped to specific numbered boundaries. One side of the street could be one boundary number, the other side of the street could be another, hence the even odd comparison.

  6. #6
    nvrwrkn is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2012
    Posts
    35
    won't output the string, same error regarding the form item.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    A text field requires delimiters in the WHERE clause, like the apostrophes in red:


    "...((GeoData!STREET_DIRECTION_CD)='" & [Forms]![Activity]![StreetNo] & "')..."
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    What exactly is the code now, and what exactly is the error? Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    nvrwrkn is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2012
    Posts
    35
    argh...added them with same error. Everywhere I use the item.

    Is this the problem? Like '" & [Forms]![Activity]![StreetNo] & "'+'*')

    adding the wildcard on the end of a text box?

  10. #10
    nvrwrkn is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2012
    Posts
    35
    can't post the db here as there's quite a bit of construction I need to keep off the net not to mention I use linked oracle tables. The entire code as is (with a few names changed to protect the innocent) is:

    Code:
    Public Function GetThing()
    Dim GeoData As DAO.Database
    Dim Location As DAO.Recordset
    Set GeoData = CurrentDb
    Dim strsql As String
    
    strsql = "SELECT TOP 1 CStr(CInt(GeoData!Area))+GeoData!Block+GeoData!Space " & _
            "FROM GeoData " & _
            "WHERE (((GeoData.EVEN_ODD_I)=IIf('" & [Forms]![Activity]![StreetNo] & "' MOD 2 = 0,'E','O')) And ((GeoData!STREET_DIRECTION_CD)='" & [Forms]![Activity]![StreetNo] & "') And ((GeoData!STREET_NME) Like '" & [Forms]![Activity]![StreetNo] & "'+'*') And (('" & [Forms]![Activity]![StreetNo] & "') Between GeoData!LOW_ADDRESS_NO And GeoData!HIGH_ADDRESS_NO)) "
            
       
       Debug.Print strsql
    
            
    End Function

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    That might be a problem when the SQL tries to run, but it sounds like you're getting some sort of compile error prior to that.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    nvrwrkn is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2012
    Posts
    35
    hmmm.....in copying/pasting some of the code I repeated the same field, StreetNo. The form field checked against STREET_DIRECTION_CD is StreetDir, the STREET_NME like is given StreetName.

    This failure to post the correct code on my part alerted me to the additional info you may need that both StreetDir and StreetName form items are ComboBoxes that are populated at the time I run the code. This works when I try this in a query but I'm not sure I can reference a combo box like I'm trying to do.

    Could THAT be the prob? Combo boxes rather than text box referenced? The reason for the combo boxes is the street names are looked up while typing so's to insure the correct street name is always entered rather than misspellings.

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Shouldn't matter, you can use combos too. Can you post an empty db with just that form in it? That might be enough to figure out what's causing the error. I must be blind but I'm not seeing it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    nvrwrkn is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2012
    Posts
    35
    gonna be a while before I can get to that, what with everything else I have to do outside this app, plus this app. Lotta stripping and renaming of objects to fit what I've been posting. I could try starting a blank db and just doing this code and this form and see what happens.

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Just so you know, you can simply export the form to a new db. You don't have to recreate it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. How to Select second Recordset from first recordset
    By FrustratedAlso in forum Programming
    Replies: 28
    Last Post: 05-10-2012, 05:45 PM
  2. IIF statement to select proper column data
    By lrydbom15 in forum Queries
    Replies: 3
    Last Post: 01-31-2012, 09:04 AM
  3. Check my Select Statement in Form
    By OMGsh Y did I say Yes in forum Forms
    Replies: 12
    Last Post: 12-07-2010, 02:13 PM
  4. Replies: 1
    Last Post: 11-13-2009, 03:03 AM
  5. select records in recordset
    By sksriharsha in forum Programming
    Replies: 3
    Last Post: 09-05-2009, 11:40 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