Creating a function to add records to tables

ca9mbu

New member
Local time
Today, 06:15
Joined
Feb 9, 2000
Messages
5
What I have at the moment is a command button that has code in the On_Click procedure that adds a new record to a given table and populates it with values from text boxes on the form.

Because I am adding records to different tables through different forms then the same code structure is repeated many times...a classic case to use a function!

I thought the easiest way to do this was create an array into which you pass the form name, table name, textbox names (on the form) and field names (in the table)

The problem I have is, different tables have different numbers of fields, and therefore the forms have different numbers of text boxes. This means I can't declare an array with a fixed number of arguments.

How do I go about declaring an array with varying numbers of arguments (presumably defined at run-time?), or is there a different approach I should be trying?

Thanx greatly, in advance

Matt
 
I've done something similar in the past but have used a DATA_SOURCE table. In this table you store unique names for each of the database tables, the number of fields in each, the name/position of their keyfield, etc, etc.

The form that I have to capture the data has controls which are named [c_one], [c_two], etc. When I click to add the record I call a function, passing the unique tablename as a parameter. This function then creates a temporary recordset for the table, using the myrec(index) method to post values into fields on a record.

Make sense??

I know this is a rambling description...you can email me on grantmcarr@hotmail.com if you would like a better description.

Hope this helps
Grant
 

Users who are viewing this thread

Back
Top Bottom