View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
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.