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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vba to add data to a table

Status
Not open for further replies.

99mel

Programmer
Oct 18, 1999
379
GB
I have done some code to create a new table and define new fields. The last fields can be of any number up to 12 (depending on what the user wants). For example there could be after the field 'start' 5 fields.<br>
<br>
I have now managed to add data using some code which from a query populates into the table. I am now wanting to add code into the remaining fields which I don't the name of (the fields that can be from 1 field to 12).<br>
<br>
Have i lost u yet? :)<br>
Anyhoo does anyone know how to read the table and get back the remaining fields?. The data going in these fields is all the same value so that makes it easier. Is there any syntax that just fills the remaining fields in the table wi th my value?<br>
<br>
Thanks for any help!
 
Not sure of the exact code<br>
But look for TableDef and FieldDef in Help<br>
I'm sure there is an example that will get all of the fields in a table<br>
It will be in a loop like:<br>
<br>
For Each field in myTable.fieldcount <br>
'List the fields.name<br>
Next<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
99mel, I was just wondering what code you used to populate your new table from the query. I am trying to do pretty much the same thing as you and any help would be really appreciated.
Thank you, Michael Kohler
mkohler@telusplanet.net
 
99mel, along with mike I also would like to see the code you used for population... Thanks
 
If using VBA try this...Used with a loop you can add data to a table.

Dim rstData as RecordSet

set rstData = CurrentDb.OpenRecordset(&quot;Name of Table&quot;, dbOpenDynaset)

With rstData
.AddNew
!Field1 = &quot;String&quot;
!Field2 = 20
!Field3 = &quot;Data&quot;
.Update
End With

set rstData = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top