Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing an append query that adds numbers to a table 1

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I am trying to write an append query to add rows to a table I was hoping to get some help. The last row in my table is the number 376. I want to add 24 rows to this table starting with 377 going up to 400. Is there any way to do this? Any help would be appreciated.
 
vba317: Your question raises two issues: First, the records in Access tables do not need to be ordered in tables; any order is fine. When you need to pull record data out (e.g. for forms, reports), you use sorting in either queries or in report design.
Secondly, as to "writing an append query," I am not sure your intentions. If creating one in query Design mode, just use the Help features; explanations are readily available. If you are trying to create an append query using code in a module, then I recommend you Dimension (dim) a variable as String, maybe call it qSQL. Then assign the sql statement for append query to the variable. Then the next line of code can be DoCmd.RunSQL qSQL.
Jeff
 
The column in the table I am refering to is meant as an ID field to track the weeks since the database was created. I am using the ID field in this table as a lookup for other columns in the table. Example if week = 380 than the other column in this column = N . If week = 350 than the other column = Y
 
If you would have your ID field in your table defined as AutoNumber, it would 'auto-magically' increment by 1 every time you add a new record.

Or you could do something like:

Code:
Dim i As Integer
Dim strSQL As String

For i = 1 to 24
  strSQL = "INSERT INTO YourTable ([blue]ID[/blue], ...) " & _
    " VALUES([blue](Select Max(ID) + 1 From YourTable)[/blue], ...)"
  DoCmd.RunSQL strSQL
next i

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top