I would like a macro to use the results from a select query to make a table.<br><br>I have a an IIF(a,1,0) in the select QRY. I want to call the results of this select QRY to make a new table. How can I code this in VB?<br><br>Thanks
Good morning!<br><br>If I understand you correctly, you want to run a select query in code and then use the results to create a new table. I am assuming that there is a reason why you can't use a Make Table query directly.<br><br>To do this, you will need to use recordsets.<br><br>The code will look something like this:<br><br>dim rstMyQuery as Recordset<br>dim rstMyTable as Recordset<br><br>set rstMyQuery = CurrentDB.OpenRecordset("Your Query Name"<br><br>'make sure that there are records returned<br>if not rstMyQuery.eof and not rstMyQuery.bof then<br> 'I'm not sure that you need this, but if <br> 'you do, create your table here. Use<br> ' the Append method of TableDefs and Fields<br> 'collection. Call your new table NewTable.<br> 'If your table will always have the same fields<br> 'create it manually. Create it in code if you <br> ' need to get the field names from the select<br> 'query <br>end if<br><br>set rstMyTable = currentdb.openrecordset("NewTable"<br>if not rstMytable.eof and not rstmytable.bof then<br>rstmytable.movefirst<br>rstMyQuery.movefirst<br><br>do until rstmyQuery.eof<br><br> rstmytable.addnew <br> rstmytable!fieldname = rstmyquery!fieldname<br> ....etc.<br> rstmytable.update<br> rsttable.movenext<br>loop<br><br><br>Let me know if you need more detail or if I totally missed the point of your question.<br><br><br>Kathryn
<br>Kathryn it is refreshing to hear from someone else.<br><br>How a about a make table query, ie.<br>"SELECT * From table1 into TableNew"<br><br>... no macros, no additional code.<br><br><br><br> <p>Amiel<br><a href=mailto:amielzz@netscape.net>amielzz@netscape.net</a><br><a href= > </a><br>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.