Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a table and prepopulate with date/times

Status
Not open for further replies.

Tadynn

Technical User
Oct 8, 2001
72
AU
Hi all,

Can someone tell me how to write a procedure that creates a table? I've done it before, and I can't remember how I did it. I think it was someone thing like:

Dim Table As TableDefs
For each fld in fld

But I've just totally forgotten.

Also within this table, I want to prepopulate 2 fields with data like the following:


Date Hour Orders Lines
21/11/2003 08:00
21/11/2003 09:00
21/11/2003 10:00
21/11/2003 11:00
21/11/2003 12:00
21/11/2003 13:00
and so on...... up to 23:00

So that the user can just key in the Orders and lines themselves.


The times although most of the time, are not always from 8pm to 11pm. So I also wanted to know if there is a way to create an array via code. ie; user enters in the start and finish time and the code will fill in the blanks.

Thanks, tadynn
 
I used this to create a table and amend the field names with entries from an array.

Set temptbl = db.CreateTableDef("DataTable")
Dim Answers() As String
m = 1
Do Until m > i
With temptbl
.Fields.Append .CreateField(Questions(m), dbText)
End With


db.TableDefs.Append temptbl

db is my database. Using DAO here.

Then used the following to enter my answers to the questions. using a loop to enter the data and move down the table. Using ADODB to enter the results.

strSQL = "INSERT INTO DataTable ("
Do Until l > i
If l = i Then
c = ")" & vbCrLf
Else
c = ","
End If
strSQL = strSQL & Questions(l) & c & " "
l = l + 1
Loop
strSQL = strSQL & "VALUES ("
k = 1

Do Until k > i
If k = i Then
b = ");"
Else
b = ","
End If
If Answers(k) = "" Then
d = "No Answer"
Else
d = Answers(k)
End If

strSQL = strSQL & "'" & d & "'" & b
k = k + 1
Loop
cnn.Execute strSQL

This cud probably be modified to do what you are wanting. Let me know if it helps.

dyarwood
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top