Results 1 to 3 of 3
  1. #1
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614

    Insert sequence of numbers in table

    I am using following code to add records to temporary table.
    Code:
    Dim i, j As Long
    Dim strSQL as String
    For i = 1 To Me.RowMax
    For j = 1 To Me.ColMax
    strSQL = "INSERT INTO [tempCounter] ([RowCount],[ColCount]) VALUES (" & i & "," & j & ");"
    CurrentDb.Execute strSQL,dbFailonerror
    Next j
    Next i
    The upper limits for RowCount and ColumnCount will be always provided through this form only.
    Can the above be achieved through an APPEND query ?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    This
    Dim i, j As Long
    doesn't do what you think.

    It will result in j as Long, but i will be Variant.
    You must explicitly DIM variables in vba.

    Dim i as Long, j as Long
    OR
    Dim i as long
    Dim j as long

  3. #3
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Thanks for pointing out the error.

    Code:
    Dim i as Long, j As Long
     Dim strSQL as String
     For i = 1 To Me.RowMax 
    For j = 1 To Me.ColMax 
    strSQL = "INSERT INTO [tempCounter] ([RowCount],[ColCount]) VALUES (" & i & "," & j & ");" 
    CurrentDb.Execute strSQL,dbFailonerror
     Next j 
    Next i
    Can above be achieved by a Query ?

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

Similar Threads

  1. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  2. Replies: 1
    Last Post: 11-29-2011, 08:43 AM
  3. Insert Into Statement with Line Numbers
    By Cheshire101 in forum Programming
    Replies: 1
    Last Post: 10-11-2010, 02:53 PM
  4. numbers
    By Balen in forum Access
    Replies: 1
    Last Post: 08-17-2010, 05:16 PM
  5. Insert Dash between set of Numbers
    By Jhankish in forum Programming
    Replies: 2
    Last Post: 04-19-2007, 08:02 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