Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Declare a public variabl

I have a userform which contains a Calendar Control. When I select a date on
the Calendar Control I want Calendar.Value to be public so that it can be
used in another module.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Declare a public variabl

Have a public variable in a standard module:

Public DVal As Date

Your UF code should be like this:

Private Sub Calendar1_Click()
DVal = Calendar1.Value
End Sub

After selecting a date and closing the UF, if you run the following you
should return the selected date:

Sub Test()
MsgBox Format(DVal, "d mmm yyyy")
End Sub

However, note that if you are invoking an error somewhere it will kill
public variables. If the above doesn't work then you likely have one.

Regards,
Greg






"Patrick Simonds" wrote:

I have a userform which contains a Calendar Control. When I select a date on
the Calendar Control I want Calendar.Value to be public so that it can be
used in another module.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Declare a public variabl

Not working and I am not sure why. The problem is that when I select a
Thursday (day 5) the Thursday_Test macro should place the value of DVal in
the active cell and then exit module. But it continues to the code after the
End If statement.

Here is my code:

From the Calendar UserForm:

Public DVal As Date

Private Sub CommandButton1_Click()
'Apply Change

DVal = Calendar1.Value
DateTest.Thursday_Test

End Sub

From the Thursday_Test Module:

Sub Thursday_Test()

Dim MyDate, MyWeekDay
MyDate = DVal 'Assign a date.
MyWeekDay = Weekday(MyDate)

If MyWeekDay = 5 Then
ActiveCell.Value = DVal
Exit Sub

End If
Unload Calendar
WrongDay.Show

End Sub















"Greg Wilson" wrote in message
...
Have a public variable in a standard module:

Public DVal As Date

Your UF code should be like this:

Private Sub Calendar1_Click()
DVal = Calendar1.Value
End Sub

After selecting a date and closing the UF, if you run the following you
should return the selected date:

Sub Test()
MsgBox Format(DVal, "d mmm yyyy")
End Sub

However, note that if you are invoking an error somewhere it will kill
public variables. If the above doesn't work then you likely have one.

Regards,
Greg






"Patrick Simonds" wrote:

I have a userform which contains a Calendar Control. When I select a date
on
the Calendar Control I want Calendar.Value to be public so that it can be
used in another module.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Declare a public variabl

Did you declare DVal in a standard module as opposed to the UF code module? I
have your code working provided it is declared in a standard module and the
Thursday_Test macro is in a standard module named "DateTest" and the UF is
named Calendar.

You could have the Thursday_Test macro contained in the UF code module and
declare DVal in the UF code module instead. It wouldn't have to be public in
this case.

Regards,
Greg


"Patrick Simonds" wrote:

Not working and I am not sure why. The problem is that when I select a
Thursday (day 5) the Thursday_Test macro should place the value of DVal in
the active cell and then exit module. But it continues to the code after the
End If statement.

Here is my code:

From the Calendar UserForm:

Public DVal As Date

Private Sub CommandButton1_Click()
'Apply Change

DVal = Calendar1.Value
DateTest.Thursday_Test

End Sub

From the Thursday_Test Module:

Sub Thursday_Test()

Dim MyDate, MyWeekDay
MyDate = DVal 'Assign a date.
MyWeekDay = Weekday(MyDate)

If MyWeekDay = 5 Then
ActiveCell.Value = DVal
Exit Sub

End If
Unload Calendar
WrongDay.Show

End Sub















"Greg Wilson" wrote in message
...
Have a public variable in a standard module:

Public DVal As Date

Your UF code should be like this:

Private Sub Calendar1_Click()
DVal = Calendar1.Value
End Sub

After selecting a date and closing the UF, if you run the following you
should return the selected date:

Sub Test()
MsgBox Format(DVal, "d mmm yyyy")
End Sub

However, note that if you are invoking an error somewhere it will kill
public variables. If the above doesn't work then you likely have one.

Regards,
Greg






"Patrick Simonds" wrote:

I have a userform which contains a Calendar Control. When I select a date
on
the Calendar Control I want Calendar.Value to be public so that it can be
used in another module.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Declare a public variabl

Thanks for your help. That was my problem (well one of many) I had not
declared in a standard module.


"Greg Wilson" wrote in message
...
Did you declare DVal in a standard module as opposed to the UF code
module? I
have your code working provided it is declared in a standard module and
the
Thursday_Test macro is in a standard module named "DateTest" and the UF is
named Calendar.

You could have the Thursday_Test macro contained in the UF code module and
declare DVal in the UF code module instead. It wouldn't have to be public
in
this case.

Regards,
Greg


"Patrick Simonds" wrote:

Not working and I am not sure why. The problem is that when I select a
Thursday (day 5) the Thursday_Test macro should place the value of DVal
in
the active cell and then exit module. But it continues to the code after
the
End If statement.

Here is my code:

From the Calendar UserForm:

Public DVal As Date

Private Sub CommandButton1_Click()
'Apply Change

DVal = Calendar1.Value
DateTest.Thursday_Test

End Sub

From the Thursday_Test Module:

Sub Thursday_Test()

Dim MyDate, MyWeekDay
MyDate = DVal 'Assign a date.
MyWeekDay = Weekday(MyDate)

If MyWeekDay = 5 Then
ActiveCell.Value = DVal
Exit Sub

End If
Unload Calendar
WrongDay.Show

End Sub















"Greg Wilson" wrote in message
...
Have a public variable in a standard module:

Public DVal As Date

Your UF code should be like this:

Private Sub Calendar1_Click()
DVal = Calendar1.Value
End Sub

After selecting a date and closing the UF, if you run the following you
should return the selected date:

Sub Test()
MsgBox Format(DVal, "d mmm yyyy")
End Sub

However, note that if you are invoking an error somewhere it will kill
public variables. If the above doesn't work then you likely have one.

Regards,
Greg






"Patrick Simonds" wrote:

I have a userform which contains a Calendar Control. When I select a
date
on
the Calendar Control I want Calendar.Value to be public so that it can
be
used in another module.










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Declare a public variabl

declare a global variable by using the global key word at the top of
your module.

Global strMyGlobalString as string

Then in your sub procedure simply use the variable as you normally
would:

strMyGlobalString = Calendar.value

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default Declare a public variabl

Also, if you terminate a procedure with "end", it resets variables.
If you want to terminate the procedure other than by falling thru the "end
sub", use "exit sub".

"Patrick Simonds" wrote:

I have a userform which contains a Calendar Control. When I select a date on
the Calendar Control I want Calendar.Value to be public so that it can be
used in another module.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sum one cell across workbook if nr of worksheets is variabl Tezza Excel Worksheet Functions 2 October 12th 09 09:59 PM
Declare and Set Public variables jlclyde Excel Discussion (Misc queries) 2 January 28th 09 02:16 PM
Public declare for Set.... zapatista66[_17_] Excel Programming 2 September 30th 05 01:29 PM
How to declare variable as public. Mark Excel Programming 3 April 7th 05 06:27 PM
PUBLIC DECLARE N10 Excel Programming 0 December 24th 04 06:50 PM


All times are GMT +1. The time now is 04:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"