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

record populating

Status
Not open for further replies.

99mel

Programmer
Joined
Oct 18, 1999
Messages
379
Location
GB
I have created a new table using VBA along with several new fields. I know how to populate a field using some code with a string provided in the code. I am wanting to populate the fields with the vlaue of a queries result.<br>
The following code is from the help but is just for a string from the code.<br>
<br>
======================================<br>
With mytab<br>
.AddNew<br>
!custname = &quot;blahyd blah&quot;<br>
======================================<br>
<br>
Am i going the wrong way about it to use a query result?<br>
<br>
<br>
=================================================<br>
With mytab<br>
.AddNew<br>
!custname = !queries!data!custnameq<br>
=================================================<br>
<br>
Thanks for any help!
 
build an 'Append query' from the 'query result'<br>
ie INSERT INTO MYTAB ( ProductID, UnitPrice )<br>
SELECT [Order Details].ProductID, [Order Details].UnitPrice<br>
FROM [Order Details];<br>
<br>
You can then run this query from VBA :<br>
MYDB.execute (&quot;INSERT INTO MYTAB ( ProductID, UnitPrice )<br>
SELECT [Order Details].ProductID, [Order Details].UnitPrice<br>
FROM [Order Details]&quot;)<br>
or if u save the query in MYDB as (qry_append) you can execute by using <br>
<br>
mydb.execute (qry_append) <br>
<br>
Alternatively U could open a recordset in VB and load it with the results of your query<br>
set myset=mydb.openrecordset(&quot;order details&quot;)<br>
set myset2 = mydb.openrecordset(&quot;MYTAB&quot;)<br>
myset.movefirst<br>
with myset2<br>
while not myset.eof <br>
.addnew<br>
!product_id= myset!product_id<br>
!etc<br>
!etc<br>
.update<br>
myset.movenext<br>
wend<br>
myset.close<br>
myset2.close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top