BBlu
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<<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.
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.
You can run everything from the button's click event, using VBA or a macro.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Never thought of that, IrogSinta. Makes sense, though.
ASKER
Great Help, Guys! I love this forum, couldn't live without it.
ASKER
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?