Steveanderson
Registered User.
- Local time
- Yesterday, 22:12
- Joined
- May 27, 2010
- Messages
- 16
I wrote a little procedure in order to add new colunms to a table
Table listedemog is a list of the columns to add
Column name: Demog
Row data: a b c d
Table Demog is the table containing all the data
Column names: a b c d e f g
Table DemogSelect is theresult table with only the columns from listedemog and the data from the demog table. ( Note: The #Req is added by default in the begining of the procedure)
The procedure will create my new table with the right columns but without any data in the columns
what am I doing wrong ?
Private Sub Commande34_Click()
Dim DB As Database
Dim Rst As Recordset
Dim NumRecords As Long
Dim M As String
DoCmd.RunSQL "SELECT Demog.[#Req] INTO DemogSelect FROM Demog;"
Set DB = CurrentDb()
Set Rst = DB.OpenRecordset("listedemog")
If Rst.RecordCount = 0 Then
Exit Sub
End If
Rst.MoveFirst
M = Rst!Demog
DoCmd.RunSQL "ALTER TABLE DemogSelect ADD COLUMN [" & M & "] TEXT(10);"
DoCmd.RunSQL "INSERT INTO DemogSelect SELECT Demog.[" & M & "] FROM Demog;"
Do While Not Rst.EOF
Rst.MoveNext
M = Rst!Demog
DoCmd.RunSQL "ALTER TABLE DemogSelect ADD COLUMN [" & M & "] TEXT(10);"
DoCmd.RunSQL "INSERT INTO DemogSelect SELECT Demog.[" & M & "] FROM Demog;"
Loop
End Sub
Table listedemog is a list of the columns to add
Column name: Demog
Row data: a b c d
Table Demog is the table containing all the data
Column names: a b c d e f g
Table DemogSelect is theresult table with only the columns from listedemog and the data from the demog table. ( Note: The #Req is added by default in the begining of the procedure)
The procedure will create my new table with the right columns but without any data in the columns
what am I doing wrong ?
Private Sub Commande34_Click()
Dim DB As Database
Dim Rst As Recordset
Dim NumRecords As Long
Dim M As String
DoCmd.RunSQL "SELECT Demog.[#Req] INTO DemogSelect FROM Demog;"
Set DB = CurrentDb()
Set Rst = DB.OpenRecordset("listedemog")
If Rst.RecordCount = 0 Then
Exit Sub
End If
Rst.MoveFirst
M = Rst!Demog
DoCmd.RunSQL "ALTER TABLE DemogSelect ADD COLUMN [" & M & "] TEXT(10);"
DoCmd.RunSQL "INSERT INTO DemogSelect SELECT Demog.[" & M & "] FROM Demog;"
Do While Not Rst.EOF
Rst.MoveNext
M = Rst!Demog
DoCmd.RunSQL "ALTER TABLE DemogSelect ADD COLUMN [" & M & "] TEXT(10);"
DoCmd.RunSQL "INSERT INTO DemogSelect SELECT Demog.[" & M & "] FROM Demog;"
Loop
End Sub
Last edited: