Results 1 to 2 of 2
  1. #1
    tharindu12 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2011
    Posts
    1

    Talking Access help needed.....


    table name : master
    Start End
    1000 1500
    2500 3000

    how to get all possible values between start and end values using VBA(sql).

    ex:
    1000
    1001
    ....
    1499
    1500
    2500
    2501
    ......
    2999
    3000



    thanks in advanced.

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    You can use a simple loop to get all numbers between two numbers:

    Example I have a Form with two TextBoxes Text0 and Text2 to type the beginning number and the ending number code is attached to the OnClick event of a Command Button.

    This code will Display all Numbers between two numbers:

    Dim intCounter as Integer
    For intCounter=Me.Text0 to Me.Text2
    msgbox intCounter
    Next


    I have used the same code combined with a Recordset to insert the numbers generated in a table Table2 in the Field Number.

    Dim intCounter as integer
    Dim rst as Object
    For intCounter = Me.Text0 To Me.Text2
    Set rst = CurrentDb.OpenRecordset("Table2")
    rst.AddNew
    rst!Number = intCounter
    rst.Update
    rst.Close
    Set rst = Nothing
    Next


    In this code I have used an Insert query to insert Data:

    Dim intCounter as Integer
    Dim strSQL as String
    For intCounter = Me.Text0 To Me.Text2
    strSQL = "INSERT INTO Table2 ( [Number] ) VALUES (" & intCounter & ");"
    CurrentDb.Execute strSQL, dbfailonerror
    Next

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

Similar Threads

  1. Example Needed for Access VB
    By boy3696 in forum Programming
    Replies: 4
    Last Post: 09-21-2010, 11:23 PM
  2. Ms Access Programers Needed
    By Dinjee in forum Access
    Replies: 0
    Last Post: 01-29-2010, 07:08 PM
  3. Replies: 0
    Last Post: 09-07-2009, 04:27 PM
  4. Replies: 4
    Last Post: 08-30-2009, 12:31 PM
  5. Access Professional Support Needed
    By Perry Mason in forum Access
    Replies: 0
    Last Post: 07-28-2009, 02:30 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