Results 1 to 5 of 5
  1. #1
    GoldenOrb is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    5

    Query for obtaining numbers between 2 fields


    Hi, Im relatively new to Access. Ive got a handle on the basics but need some help.

    Im trying to create a database for mailing specific addresses in a street.

    What fields I have is a {Field 1}Start_Street_number (ie House 10) and a {field 2}End_Street_number (ie House 20)... Street Name, Street type (which is its on query options) and Suburb (which is its on query options).

    What result I am chasing is entering the Start_ Street_number and End_Street_number to have access generate all the numbers in including and between.

    In the above mentioned example... Start_Street_number (ie House 10) and a End_Street_number (ie House 20)
    Enter house 10, Enter house 20... Smith Street..... Apple Valley

    To obtain result of
    10 Smith Street Apple Valley... 11 Smith Street Apple Valley.. and so on up until 20 Smith Street Apple Valley.

    Does anyone have any hints on how to achieve this please.

    Thanks in advance
    Geoff

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Here's a basic of queries that you missed: a query can't retrieve records that don't exist. You want to create records using the street number fields as parameters. A VBA procedure could write records to a 'temp' table. This would involve a recordset, loop structure, and sql INSERT action. Something like:

    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    rs.Open "SELECT * FROM tablename WHERE your criteria here;", CurrentProject.Connection, adOpenStatic, adLockPessimistic
    CurrentDb.Execute "DELETE FROM temptablename"
    For i = rs!Start_Street_Number to rs!End_Street_Number
    CurrentDb.Execute "INSERT INTO temptablename(HouseNumber, StreetName, StreetType, Suburb) VALUES(" & i & ", " & rs!StreetName & ", " & rs!StreetType & ", " & rs!Suburb & ")"
    Next

    This method requires setting a VBA reference to: Microsoft ActiveX Data Objects 2.8 Library
    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.

  3. #3
    GoldenOrb is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    5
    Cool thanks, Ive been meaning to get back to this forum but just after I posted a few days later my hard drive died on me with all my links.

    Ill give this a shot, thanks again

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    I was assuming that Start_Street_number and End_Street_number fields have only numeric values, no text.
    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.

  5. #5
    GoldenOrb is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    5
    Yeah thanks thats fine... Stupid thing is the most the houses in this dust bowl dont have letter boxes anyway due to all the mail theft, so all Im really doing is trying to appease the bosses in something that wont probably work or be received... well until next months crazy idea comes up. Ill give that a go tonight.

    Thanks

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

Similar Threads

  1. Replies: 3
    Last Post: 09-05-2012, 12:47 PM
  2. Obtaining a value in a form from a table
    By Cedarguy in forum Forms
    Replies: 8
    Last Post: 05-17-2012, 03:21 PM
  3. Assigning numbers to certain fields
    By smartflashes in forum Programming
    Replies: 6
    Last Post: 01-19-2012, 05:14 PM
  4. Replies: 0
    Last Post: 12-29-2011, 05:21 PM
  5. Obtaining .net Webservice Data
    By Azmail in forum Programming
    Replies: 0
    Last Post: 01-26-2011, 08:36 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