Link to home
Start Free TrialLog in
Avatar of BBlu
BBluFlag for United States of America

asked on

Macro on Form to run query, then execute a subroutine

I got some help from EE in successfully writing a subroutine that imports a spreadsheet into a table.

I then realized that I need to delete all the records in the table first, so I wrote a delete records query.

How can I create a macro that first calls the query to delete the records, then calls the subroutine to import the new records?
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
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
SOLUTION
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
Avatar of BBlu

ASKER

Thanks, guys!

imnorie,
I do have a button on a form, but I want to do it all in one step.

Jim,
Can I use the openquery action to run the query in the first step?  And do you know why it's necessary to change the subroutine to a function?
<<Can I use the openquery action to run the query in the first step?>>

  Openquery is for use with a select query.

<<And do you know why it's necessary to change the subroutine to a function?>>

 Macro's expect a return value from the called code, so it must be a function (that's the only difference between a function and a sub; one returns a value, the other does not).

Jim.
Avatar of Norie
Norie

You can run everything from the button's click event, using VBA or a macro.
SOLUTION
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
Avatar of BBlu

ASKER

Never thought of that, IrogSinta.  Makes sense, though.
Avatar of BBlu

ASKER

Great Help, Guys!  I love this forum, couldn't live without it.