How do I Enable a Button from a Module after a successful run?

K

KmhComputer

Hi, I hope you can help me. I have a screen with several buttons on the
button that I enable and disable based on user selections/actions.

I will call this main form: Main_Form.

One button runs a Module that imports a bunch of data and does a lot of
mathematical calculations etc. Once this procedure has been run and only if
it has been run "successfully" I would like two buttons on my main form to
become enabled.

I will call the buttons I want Enabled: Edit_Record and Calc_Coeffs.

How can I tell Access using VBA in my module to enable the buttons on the
form. It would be great if I could do this from my module.

Thanks so much.
 
R

Rick Brandt

KmhComputer said:
Hi, I hope you can help me. I have a screen with several buttons on
the button that I enable and disable based on user selections/actions.

I will call this main form: Main_Form.

One button runs a Module that imports a bunch of data and does a lot
of mathematical calculations etc. Once this procedure has been run
and only if it has been run "successfully" I would like two buttons
on my main form to become enabled.

I will call the buttons I want Enabled: Edit_Record and Calc_Coeffs.

How can I tell Access using VBA in my module to enable the buttons
on the form. It would be great if I could do this from my module.

Thanks so much.

If the code is running in the form's own module then...

Me!Edit_Record.Enabled = True
Me!Calc_Coeffs.Enabled = True

If from a standard module then...

Forms!Main_Form!Edit_Record.Enabled = True
Forms!Main_Form!Calc_Coeffs.Enabled = True
 
K

KmhComputer

Maybe I am doing all this the hard way. It doesn't appear to be working.

Here's the outline:
1. On my main form, the user clicks on a button to import a file.
2. Once the button is clicked, I popup a Access Dialog to locate the import
file.
3.From here, this dialog box calls a macro whose only purpose to is call the
Calc_Function() in a module I wrote. Once it calls this macro it closes the
Dialog box window.
4. Run the module
5. If successful run - return to main form with the new buttons enabled.

I put in your code and it still doesn't do it. Like I said, maybe I am
taking the long way around the barn here and Access is getting lost.

When the module is run, the correct record does appear on my main form, but
those buttons won't cooperate.
 
R

Rick Brandt

KmhComputer said:
Maybe I am doing all this the hard way. It doesn't appear to be
working.

Here's the outline:
1. On my main form, the user clicks on a button to import a file.
2. Once the button is clicked, I popup a Access Dialog to locate the
import file.
3.From here, this dialog box calls a macro whose only purpose to is
call the Calc_Function() in a module I wrote. Once it calls this
macro it closes the Dialog box window.
4. Run the module
5. If successful run - return to main form with the new buttons
enabled.

I put in your code and it still doesn't do it. Like I said, maybe I
am taking the long way around the barn here and Access is getting
lost.

When the module is run, the correct record does appear on my main
form, but those buttons won't cooperate.

Just to correct your terminology, one does not run a "Module". A module
contains sub-routines and functions and one can run either of those. I assume
you are running a sub-routine within the module that you are speaking of. Is
that where you placed the lines of code to enable the buttons (inside the sub)?
 
K

KmhComputer

Sorry about the terminology. I'm a little tired and not thinking straight.

Yes. I wrote a subroutine that is in a Module sitting under the Module tab
in Access. Yes, I placed the Button commands at the end o this module.

I have a simple macro under the Macros tab that calls this subroutine.

I have two forms under Forms, the main form and the Dialog File Locate form.
 
R

Rick Brandt

KmhComputer said:
Sorry about the terminology. I'm a little tired and not thinking
straight.

Yes. I wrote a subroutine that is in a Module sitting under the
Module tab in Access. Yes, I placed the Button commands at the end
o this module.

I have a simple macro under the Macros tab that calls this subroutine.

I have two forms under Forms, the main form and the Dialog File
Locate form.

Well if those two lines of code run without errors then the buttons should be
enabled afterwards. Try adding a breakpoint and stepping through the code one
line at a time to see if those two lines are really being executed.
 
K

KmhComputer

Found it! Thanks so much. I just had to move the lines up a little bit in
my code. I guess I shouldn't attemp to code when I am tired. Thanks so much
for your help. I really appreciate it!

Kathy
 
Top