ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Passing variables between forms (https://www.excelbanter.com/excel-programming/342147-passing-variables-between-forms.html)

Sami82[_8_]

Passing variables between forms
 

Hi All,

I have a 2 forms which rely heavily on a variable called -Vendor-. I
have declaired it in the first form as:

-Public Vendor As String-

The only problem is that the second form fails to pick up the data in
this variable.

Can anyone help me please?

Thank you :)


--
Sami82
------------------------------------------------------------------------
Sami82's Profile: http://www.excelforum.com/member.php...o&userid=27111
View this thread: http://www.excelforum.com/showthread...hreadid=474024


Norman Jones

Passing variables between forms
 
Hi Sami82,

Try moving

Public Vendor As String


from the userform module to the head of a standard module.

---
Regards,
Norman



"Sami82" wrote in
message ...

Hi All,

I have a 2 forms which rely heavily on a variable called -Vendor-. I
have declaired it in the first form as:

-Public Vendor As String-

The only problem is that the second form fails to pick up the data in
this variable.

Can anyone help me please?

Thank you :)


--
Sami82
------------------------------------------------------------------------
Sami82's Profile:
http://www.excelforum.com/member.php...o&userid=27111
View this thread: http://www.excelforum.com/showthread...hreadid=474024




Dr. Stephan Kassanke

Passing variables between forms
 

"Sami82" schrieb im
Newsbeitrag ...

Hi All,

I have a 2 forms which rely heavily on a variable called -Vendor-. I
have declaired it in the first form as:

-Public Vendor As String-

The only problem is that the second form fails to pick up the data in
this variable.

Can anyone help me please?

Thank you :)


--
Sami82
------------------------------------------------------------------------
Sami82's Profile:
http://www.excelforum.com/member.php...o&userid=27111
View this thread: http://www.excelforum.com/showthread...hreadid=474024


Sami82,

declare ist as a public variable in a module, not in a form (which makes it
globally accessible).

cheers,
Stephan



Sami82[_9_]

Passing variables between forms
 

Thank you for your speedy reply,

Can this be situated in the "ThisWorkbook" section, because the macr
runs automatically on startup

--
Sami8
-----------------------------------------------------------------------
Sami82's Profile: http://www.excelforum.com/member.php...fo&userid=2711
View this thread: http://www.excelforum.com/showthread.php?threadid=47402


Norman Jones

Passing variables between forms
 
Hi Sam82,

Can this be situated in the "ThisWorkbook" section, because the macro
runs automatically on startup?


No, the global Vendor variable should be declared at the top of a standard
module.

Should you wish to initialise the Vendor variable in the workbook's opening
event, try (in the ThisWorkbook module):

Private Sub Workbook_Open()
Vendor = "Joe Bloggs Inc"
End Sub

---
Regards,
Norman



"Sami82" wrote in
message ...

Thank you for your speedy reply,

Can this be situated in the "ThisWorkbook" section, because the macro
runs automatically on startup?


--
Sami82
------------------------------------------------------------------------
Sami82's Profile:
http://www.excelforum.com/member.php...o&userid=27111
View this thread: http://www.excelforum.com/showthread...hreadid=474024




Sami82[_10_]

Passing variables between forms
 

Hi All,

I have transferred this to a seperate "startup" module which is called
in "ThisWorkbook". Only problem is now I am getting an error when it
gets to my first Public line, the error is:

Compile error:
Invalid attribute in Sub or Function"

How can I fix this but still be able to use my variables across
multiple forms?

Thank you once again


--
Sami82
------------------------------------------------------------------------
Sami82's Profile: http://www.excelforum.com/member.php...o&userid=27111
View this thread: http://www.excelforum.com/showthread...hreadid=474024


Dr. Stephan Kassanke

Passing variables between forms
 

"Sami82" schrieb im
Newsbeitrag ...

Hi All,

I have transferred this to a seperate "startup" module which is called
in "ThisWorkbook". Only problem is now I am getting an error when it
gets to my first Public line, the error is:

Compile error:
Invalid attribute in Sub or Function"

How can I fix this but still be able to use my variables across
multiple forms?

Thank you once again


--
Sami82


Declare your variable before any sub

Public Vendor As String

Sub xyz
....
end sub

Stephan



Sami82[_13_]

Passing variables between forms
 

Worked a treat.

Thank you!


--
Sami82
------------------------------------------------------------------------
Sami82's Profile: http://www.excelforum.com/member.php...o&userid=27111
View this thread: http://www.excelforum.com/showthread...hreadid=474024



All times are GMT +1. The time now is 10:18 AM.

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