473,383 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to process an array of fieldnames and fieldtypes in FN creating table

MLH
What might a FN look like to put the following lines in if such
FN accepted an array of desired fieldnames and fieldtypes?
I would like to have the functional lines that follow in a FN
that accepted an array of data that looked like this:

"VehicleJobID", dbLong
"WannaBill", dbBoolean

10 If TableOrQueryExists("", "TempTable") Then DoCmd.DeleteObject
acTable, "TempTable"
20 Dim dbs As Database, tdf As TableDef, fld As Field
30 Set dbs = CurrentDb
40 Set tdf = dbs.CreateTableDef("TempTable")
50 Set fld = tdf.CreateField("VehicleJobID", dbLong)
60 tdf.Fields.Append fld
70 Set fld = tdf.CreateField("WannaBill", dbBoolean)
80 tdf.Fields.Append fld
90 tdf.Fields.Refresh
100 dbs.TableDefs.Append tdf
110 dbs.TableDefs.Refresh
120 Set dbs = Nothing
130 Set tdf = Nothing

I'm sure lines 50, 60, 70 and 80 will change - to what, I don't know.
Aug 31 '06 #1
1 1241

MLH wrote:
What might a FN look like to put the following lines in if such
FN accepted an array of desired fieldnames and fieldtypes?
I would like to have the functional lines that follow in a FN
that accepted an array of data that looked like this:

"VehicleJobID", dbLong
"WannaBill", dbBoolean

10 If TableOrQueryExists("", "TempTable") Then DoCmd.DeleteObject
acTable, "TempTable"
20 Dim dbs As Database, tdf As TableDef, fld As Field
30 Set dbs = CurrentDb
40 Set tdf = dbs.CreateTableDef("TempTable")
50 Set fld = tdf.CreateField("VehicleJobID", dbLong)
60 tdf.Fields.Append fld
70 Set fld = tdf.CreateField("WannaBill", dbBoolean)
80 tdf.Fields.Append fld
90 tdf.Fields.Refresh
100 dbs.TableDefs.Append tdf
110 dbs.TableDefs.Refresh
120 Set dbs = Nothing
130 Set tdf = Nothing

I'm sure lines 50, 60, 70 and 80 will change - to what, I don't know.
Abstract out a little.... something like this... (test first...)

I'm passing in an array of (Fields(column 0) and Types (column 1)) so I
can process the lot inside the routine. then I can just loop through
the array and do the field creation and appending the field to the
table.

public sub AddFieldsToTable(byval strTable as string, byval
arrFieldsAndTypes As Variant)

dim intCounter as integer

10 If TableOrQueryExists("", strTable) Then DoCmd.DeleteObject
acTable, strTable
20 Dim dbs As Database, tdf As TableDef, fld As Field
30 Set dbs = CurrentDb
40 Set tdf = dbs.CreateTableDef(strTable)
for intCounter = lbound(arrFieldsAndTypes) to ubound(arrFieldsAndtypes)

50 Set fld = tdf.CreateField(arrFieldsAndTypes(intCounter,0),
arrFieldsAndtypes(intCounter,1)
60 tdf.Fields.Append fld
next intCounter

90 tdf.Fields.Refresh
100 dbs.TableDefs.Append tdf
110 dbs.TableDefs.Refresh
120 Set dbs = Nothing
130 Set tdf = Nothing

End Sub

Aug 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Josep | last post by:
Hi, I'd like to poll a database and get the table contents, as well as the field names from that table. I've been to php.net but this time I cannot find something helpful. I can get the data,...
5
by: Paul C-T | last post by:
Hi, Am I trying to be too clever here? I am trying to write a PHP page to enable me to enter values into a form then write those values to a text file. I want to use the form & table that...
7
by: | last post by:
How do I get to the fieldnames of a table in a recordset? I have a recordset which I output into HTML. And on data from certian columns I need to perform different actions. I would like to...
4
by: Little PussyCat | last post by:
Hello, I have had a request, one of our tables is used as a report and I have been asked that all fieldnames for months have dashes in them, like Jan-05 instead of Jan05 and so on... Now what...
5
by: nescio | last post by:
hello, i have made an application in php so that people can make, on the fly, a form. when they submit the form there is a javascript formvalidation. because we do not know how many fields...
16
by: frizzle | last post by:
Hi there! I'd like to create a function which input is the result of a mySQL query. The output should be exactly the same, only not a mySQL result array, but a 'real' array. So it should also...
6
by: Gerrit | last post by:
Hello, I try to display the fieldnames and the primary key of a table, with this code: using System; using System.Collections.Generic; using System.Text; using System.Data; using...
2
by: john | last post by:
In the query builder I made an edit-query in which I have linked table A to table B on IDnr. For every record that matches I want 5 fields of table A to get the values of corresponding fields in...
1
by: The Hajj | last post by:
I've got an app I'm working on and a benefit to my users versus the old application is dynamic forms. I didn't want to do it at first but I figured it's something I'll have to do and the added...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.