ThomasLafferty
Instructor
I have a table called CNIDMaster with a single field called CNID whose data type is Long Integer (not auto increment the numbers are hand entered.)
How can I use VBA to insert a sequential series of Long Integers into the table based upon a start and end integer that I specify on a form? Here's what I have for code so far, and I have an error in my SQL string someplace, but I'm stumped.
Any ideas?
Born once die twice; born twice die once.
How can I use VBA to insert a sequential series of Long Integers into the table based upon a start and end integer that I specify on a form? Here's what I have for code so far, and I have an error in my SQL string someplace, but I'm stumped.
Code:
Private Sub btn_Search_Click()
'*****VARIABLE DECLARATION*****
Dim lngIncrementCNID As Long, strSQL As String
'Initialize variable
lngIncrementCNID = Me.CNIDStart.Value
While lngIncrementCNID <= Me.CNIDEnd.Value
strSQL = "INSERT INTO [CNIDMaster]," _
& "SELECT [CNID] FROM [CNIDMASTER],"
[!]'Probably need line here to refer to lngIncrementID[/!]
DoCmd.SetWarnings False
'Error occurs here
[highlight]DoCmd.RunSQL strSQL[/highlight]
DoCmd.SetWarnings True
lngIncrementCNID = lngIncrementCNID + 1
Wend 'CNIDs successfully added
End Sub
Any ideas?
Born once die twice; born twice die once.