PC Review


Reply
Thread Tools Rate Thread

Appending results of loop to a table

 
 
Cheese_whiz
Guest
Posts: n/a
 
      28th Aug 2008
Hi all,

I want to loop through some object collections (objects in the collections,
to be precise) and get system values, and then append the results to a table
in the current db. Right now, the best I know how to do is create a text
file, loop through and append the object/value combinations as a new line in
the text file, then, when the loop ends use the transfertext method to import
the lines into a table and then delete the text file.

It works, but it seems like a round about way of doing things.

Is there a way to just take each of these combinations (object/value), as
I'm going through the loop, and append them to a table?

Thanks,
CW
 
Reply With Quote
 
 
 
 
Michel Walsh
Guest
Posts: n/a
 
      28th Aug 2008
If you want add one record by pair, you can, in the loop, use:


Dim db As Database : Set db=CurrentDb 'outside the loop

For ..

...
db.Execute "INSERT INTO tableName( field1, field2) VALUES(" &
value1 & ", " & value2 & ")" , dbFailOnError

Next ...


Note that I assumed value1 and value2 to be numerical. If both are strings,
you need a delimiter:


db.Execute "INSERT INTO tableName(field1, field2) VALUES("""& value1
& """,""" & value2 & """)", dbFailOnError


(and that assume neither value1, neither value2 has a " in it, as data,
such as: 5' - 6" 1/8 )


If value1 is a string and value2 a date_time:


db.Execute "INSERT INTO tableName(field1, field2) VALUES("""& value1
& """,#" & Format(value2, "mm/dd/yyyy hh:nn:ss") & "#)", dbFailOnError


Sure, if the values can be picked from a control in an open form, it may be
easier:

DoCmd.RunSQL "INSERT INTO tableName(field1, field2)
VALUES(FORMS!formName!ControlName1, FORMS!formName!ControlName2)"


since then no delimiter will be required.



You may also chose to append the data through an open recordset, but opening
a recordset JUST for that purpose sounds a waste of time.



Vanderghast, Access MVP


"Cheese_whiz" <(E-Mail Removed)> wrote in message
news:24EF721F-C1FE-4809-B9D2-(E-Mail Removed)...
> Hi all,
>
> I want to loop through some object collections (objects in the
> collections,
> to be precise) and get system values, and then append the results to a
> table
> in the current db. Right now, the best I know how to do is create a text
> file, loop through and append the object/value combinations as a new line
> in
> the text file, then, when the loop ends use the transfertext method to
> import
> the lines into a table and then delete the text file.
>
> It works, but it seems like a round about way of doing things.
>
> Is there a way to just take each of these combinations (object/value), as
> I'm going through the loop, and append them to a table?
>
> Thanks,
> CW



 
Reply With Quote
 
Cheese_whiz
Guest
Posts: n/a
 
      28th Aug 2008
Thanks!

Just what I needed.

CW

"Michel Walsh" wrote:

> If you want add one record by pair, you can, in the loop, use:
>
>
> Dim db As Database : Set db=CurrentDb 'outside the loop
>
> For ..
>
> ...
> db.Execute "INSERT INTO tableName( field1, field2) VALUES(" &
> value1 & ", " & value2 & ")" , dbFailOnError
>
> Next ...
>
>
> Note that I assumed value1 and value2 to be numerical. If both are strings,
> you need a delimiter:
>
>
> db.Execute "INSERT INTO tableName(field1, field2) VALUES("""& value1
> & """,""" & value2 & """)", dbFailOnError
>
>
> (and that assume neither value1, neither value2 has a " in it, as data,
> such as: 5' - 6" 1/8 )
>
>
> If value1 is a string and value2 a date_time:
>
>
> db.Execute "INSERT INTO tableName(field1, field2) VALUES("""& value1
> & """,#" & Format(value2, "mm/dd/yyyy hh:nn:ss") & "#)", dbFailOnError
>
>
> Sure, if the values can be picked from a control in an open form, it may be
> easier:
>
> DoCmd.RunSQL "INSERT INTO tableName(field1, field2)
> VALUES(FORMS!formName!ControlName1, FORMS!formName!ControlName2)"
>
>
> since then no delimiter will be required.
>
>
>
> You may also chose to append the data through an open recordset, but opening
> a recordset JUST for that purpose sounds a waste of time.
>
>
>
> Vanderghast, Access MVP
>
>
> "Cheese_whiz" <(E-Mail Removed)> wrote in message
> news:24EF721F-C1FE-4809-B9D2-(E-Mail Removed)...
> > Hi all,
> >
> > I want to loop through some object collections (objects in the
> > collections,
> > to be precise) and get system values, and then append the results to a
> > table
> > in the current db. Right now, the best I know how to do is create a text
> > file, loop through and append the object/value combinations as a new line
> > in
> > the text file, then, when the loop ends use the transfertext method to
> > import
> > the lines into a table and then delete the text file.
> >
> > It works, but it seems like a round about way of doing things.
> >
> > Is there a way to just take each of these combinations (object/value), as
> > I'm going through the loop, and append them to a table?
> >
> > Thanks,
> > CW

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Appending Random Results? Lee Harris Microsoft Excel Worksheet Functions 8 8th Dec 2005 05:26 PM
Appending records to a recordset with a for loop rmullen Microsoft Access Forms 0 6th Dec 2005 02:59 PM
Appending recordset with for loop rmullen Microsoft Excel Programming 0 6th Dec 2005 02:51 PM
Appending query results into Excel spreadsheet Debbie Wisdom Microsoft Excel Worksheet Functions 0 30th Sep 2003 11:02 PM
Re: Oracle Ref Cursor, Appending results David Browne Microsoft ADO .NET 1 24th Aug 2003 07:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:00 PM.