ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Running Code From Controls On Other Forms (https://www.excelbanter.com/excel-programming/307755-running-code-controls-other-forms.html)

bazman1uk

Running Code From Controls On Other Forms
 
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

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

Running Code From Controls On Other Forms
 
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.

--
Regards,
Tom Ogilvy




"bazman1uk " wrote in message
...
As I am not allowed to use Access for a project, I am having to make
Exce2002 work/look like Access.

My utility is basically just a load of forms with commandbuttons, text
and listboxes where values entered/selected are placed into the
woksheets behind the forms where formulas calculate values. Once
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 now
need to setup an option where I can click one commandbutton and it will
go off and open each form in turn, enter the relevant values (and so
enter into the worksheets and let the formulas calculate), and then run
the commandbutton on each form that adds the values to the relevant
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 the
commandbuttons but no joy.

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

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

Any ideas ASAP please?

Thanks

Barry


---
Message posted from http://www.ExcelForum.com/




bazman1uk[_2_]

Running Code From Controls On Other Forms
 
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

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

Running Code From Controls On Other Forms
 
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

--
Regards,
Tom Ogilvy


"bazman1uk " wrote in message
...
Tom,

Is not so much the problem of putting the vlues in the boxes. That woks
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 something
like this.

Private Sub commandbutton1_Click()

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

End Sub

Baz


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 03:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com