whojstall11
Registered User.
- Local time
- Today, 12:23
- Joined
- Sep 7, 2011
- Messages
- 94
I have some code that creates a table based off another table. This code works perfect but Im trying to alter my ID field and change it to an auto increment. How can I fix my code so that it alters my ID field?
Code:
Private Sub Command0_Click()
'OBJECTIVE: to build a table by extracting some fields from a main database
Dim rst As Recordset
Dim strSQL As String
Dim strSQL2 As String
Dim intCount As Integer
Dim intNumFields As Integer
Dim i As Integer
Dim strRecords() As String
Dim strFields As String
Dim intStatus As Integer
'A query to a "main frame computer"
strSQL2 = " ALTER TABLE ImportFundedCardstbl MODIFY ID int(4) auto_increment;"
strSQL = "SELECT DISTINCT ID,[Name],[Card Number],Amount,[Trans Linker],[Funding Account Balance] FROM ImportFundedCardstbl"
Set rst = CurrentDb.OpenRecordset(strSQL)
'LOAD ARRAY FOR FIELD NAMES FROM THE RST
'FIND THE # OF RECORDS IN THIS SET...
rst.MoveLast
rst.MoveFirst
'Total number of records in this recordset
intCount = rst.RecordCount - 1 '0-based
i = 0
intNumFields = rst.Fields.Count
'strFields = rst.Fields(0).Name 'for 1 field name
strFields = rst.Fields(0).Name & "," & rst.Fields(1).Name & "," & rst.Fields(2).Name & "," & rst.Fields(3).Name & "," & rst.Fields(4).Name & "," & rst.Fields(5).Name
Do Until rst.EOF
'Store the values of the query in an array...
ReDim Preserve strRecords(i)
'strRecords(i) = rst.Fields(0) 'for 1 field
strRecords(i) = rst.Fields(0) & "," & rst.Fields(1) & "," & rst.Fields(2) & "," & rst.Fields(3) & "," & rst.Fields(4) & "," & rst.Fields(5)
'Debug.Print strRecords(i)
i = i + 1
rst.MoveNext
Loop
'rst.Close
Close
Set rst = Nothing
'BUILD A CUSTOM TABLE BASED ON THE FIELD NAMES IN THE ARRAY...
intStatus = CreateTable(strFields, strRecords(), intNumFields, Me.txtNewTableName)
If intStatus = True Then
MsgBox "Table created and data entered successfully"
End If
End Sub