Running Code From Controls On Other Forms

B

bazman1uk

As I am not allowed to use Access for a project, I am having to mak
Exce2002 work/look like Access.

My utility is basically just a load of forms with commandbuttons, tex
and listboxes where values entered/selected are placed into th
woksheets behind the forms where formulas calculate values. Onc
calculated, the totals values are entered into tables below
like an entry in a datasheet view

The whole utility works fine in standard manual entry mode, but I no
need to setup an option where I can click one commandbutton and it wil
go off and open each form in turn, enter the relevant values (and s
enter into the worksheets and let the formulas calculate), and then ru
the commandbutton on each form that adds the values to the relevan
table below. I can't get it to work.

Here's an example of the code

frmRMSelected.Show
Run frmRMSelected.cmdRMAdd
frmRoadmap.txtRMItemDesc = itemdesc
frmRoadmap.txtRMItemNo = "12"
Run frmRoadmap.cmdRMSaveNew
Me.Hide

I originally tried to invoke the Click Event (without Run) of th
commandbuttons but no joy.

This code is supposed to show the frmRMSelected form and then click o
the cmdRMAdd button to initiate it's code. It does the rest but ignore
the "Run " lines

My only option at present is to put all the code from all the form
into one funcvtion and run that. That would be massive and messy.

Any ideas ASAP please?

Thanks

Barr
 
T

Tom Ogilvy

I think it would be messier writing the code to populate the boxes, then
executing a click event just to reuse your code. Sounds like you just need
to reorganize, rewrite your procedures to facilite the functionality you
need.
 
B

bazman1uk

Tom,

Is not so much the problem of putting the vlues in the boxes. That wok
OK. It's running the code of the command buttons.

I need to be able to do this.

From say Form1

Click on Form1.commandbutton1

This then opens Form2
Runs Form2.commandbutton1
then run Fom2.commandbutton2
then hides Form2

I effectively want the code of Form1.commandbutton1 to be somethin
like this.

Private Sub commandbutton1_Click()

Form2.Show
Form2.commandbutton1_Click
Form2.commandbutton2_Click
Form2.Hide

End Sub

Ba
 
T

Tom Ogilvy

You don't need to show form2 and in fact, that would stop your code from
executing. In form2 you would have to make all the event code Public rather
than private

Private Sub commandbutton1_Click()

Load Form2
Form2.commandbutton1_Click
Form2.commandbutton2_Click
Unload Form2
End Sub
 
Top