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.
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.
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