I loop from vba code for excel a vlaue in sheet ( are year 2001,2010,1958,....) with a for next, i loop only distinct value from column.
I just have a databse in c:\mydatabse.mdb.
How to create new table named YEARS with the fileds of loop in sheet column?
Possible with ado or dao code in vba for excel?
Note:
i just have an active ADO connection named myconn
create table in database programaticlly
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
create table in database programaticlly
Last edited by sal21 on 16 Jul 2010, 13:30, edited 1 time in total.
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: create table in database programaticlly
Do you want to create a separate field for each year, or do you want a single field, with the years as values (i.e. a record for each year)?
You haven't reacted to the reply in Post=22498 yet...
You haven't reacted to the reply in Post=22498 yet...
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: create table in database programaticlly
each filed for yeach year of the loop...HansV wrote:Do you want to create a separate field for each year, or do you want a single field, with the years as values (i.e. a record for each year)?
You haven't reacted to the reply in Post=22498 yet...
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: create table in database programaticlly
OK. What type of data do you want to store in the fields? Text (if so, how long should the field be), or numbers (if so, whole numbers or numbers with decimals), or dates, or ...?
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: create table in database programaticlly
numbers....HansV wrote:OK. What type of data do you want to store in the fields? Text (if so, how long should the field be), or numbers (if so, whole numbers or numbers with decimals), or dates, or ...?
i want to store a numbers in column filed. with the format 000.000.000
Note:
during the creation is possible to indexed the fileds?
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: create table in database programaticlly
Do you want an index on each field? If so, why? In general, it is not a good idea to index all fields in a table.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: create table in database programaticlly
OK No index in fileds...HansV wrote:Do you want an index on each field? If so, why? In general, it is not a good idea to index all fields in a table.
The teacher are you
Sorry...
before to create the list of year fileds i need to create a first field (indexed) with name AGENCY
sorry
ops i have found a code and my idea is:
........
Set adoxTable = New ADOX.Table
With adoxTable
.Name = "ANNO_AGENZIE"
for i to ....
my_var_year=sheets range A & i
.Columns.Append "my_var_year", adVarWChar, 4
next i
'.Columns.Append "ItemDescription", adVarWChar, 100
' .Columns.Append "ItemValue", adVarWChar, 4
' .Keys.Append "PrimaryKeyItemID", adKeyPrimary, "ItemID"
End With
........
wath you think about?
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: create table in database programaticlly
Let's say that the variable in the loop that contains the year is lngYear.
Code: Select all
Dim strSQL As String
' Before the loop:
strSQL = "CREATE TABLE YEARS (AGENCY Long"
...
' Within the loop:
strSQL = strSQL & ", [" & lngYear & "] Long"
...
' After the loop:
strSQL = strSQL & ")"
myconn.Execute strSQL
' Add the index on AGENCY:
strSQL = "CREATE INDEX AGENCYINEX ON YEARS (AGENCY ASC)"
myconn.Execute strSQL
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: create table in database programaticlly
No comments!HansV wrote:Let's say that the variable in the loop that contains the year is lngYear.
myconn.Execute strSQLCode: Select all
Dim strSQL As String ' Before the loop: strSQL = "CREATE TABLE YEARS (AGENCY Long" ... ' Within the loop: strSQL = strSQL & ", [" & lngYear & "] Long" ... ' After the loop: strSQL = strSQL & ")" myconn.Execute strSQL ' Add the index on AGENCY: strSQL = "CREATE INDEX AGENCYINEX ON YEARS (AGENCY ASC)"