Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Access Query / Macro

I wanted to create a new version of an Access Query that selects MORE columns from a table in the current version.

I selected the existing query, did a save as & gave it a different name.

I added the new fields & saved the query.

Then I wrote a Macro to run the new query; then I ran the Macro.

See attached screen shots.

When the Macro is run, it produces the SAME result as the old Macro/query. The new columns are NOT there.

I need to know what I am doing wrong; of course, I can send more screen shots if needed.

Thanks
LSS-MACR-Mo-2.jpg
Extr-Cust-actv-new.jpg
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

with the query viewed in datasheet,  do right click in any of the column name, and select  Unhide field, see if there are columns with the check box unchecked.

another option is,
try creating a NEW query, select all the columns that you need and save.
Avatar of Richard Korts

ASKER

Thanks.

I discovered (accidentally) that if I run the query DIRECTLY (Not from the Macro), it produces the right results.

So it must be the macro.

I attache the two steps of the macro; the Transder Text step must have a problem. Do you see any issues?

PS - This is Access 2003.

Thanks
Macro-Step-1.jpg
Macro-Step-2.jpg
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When the Macro is run, it produces the SAME result as the old Macro/query. The new columns are NOT there.

You can't achieve what you're looking for with a static query.  You need something dynamic that can able to select ALL fields from the specified table.

Sub runMyQuery()
   dim rs as Recordset
   dim sFile as string, iFile as integer
   iFile = freefile()
   sFile = "mo\lss_extr_cust_new.csv"
   Open sFile For Output as iFile
   set rs = currentDB.OpenRecordset("SELECT * FROM myTable")
   do until rs.EOF
     write #iFile, rs(0) & "," & rs(1) & "," & rs(2) '....and so forth
      rs.MoveNext
   loop 
   rs.close
   close iFile
End Sub

Open in new window

Opening the query isn't necessary.  All you need to do is to run the TransferText.  The problem is with the TransferText.  Make sure it is executing the new query rather than the old one.  The TransferText runs the specified query to create the export file.  It doesn't use the query you opened.
I removed the Transfer Specification Name; left it blank.

It works perfectly.

The help implies that, so I tried it.