Variable defined in a function

S

Shri

Hi,

I have a below function in a form.

****
Private Function OfficeClosed(TheDate) As Integer

Dim Date_export As Date

OfficeClosed = False

' Test for Saturday or Sunday.
If Weekday(TheDate) = 2 Then
OfficeClosed = True
Date_export = Date - 1
Else
Date_export = Date
End If

End Function

****

I need to use the variable "Date_export" defined above in a sub procedure.
I have below two lines of code in a sub proc. But the code doesn't work.

****
Call OfficeClosed(Date)
exportlocation.Value = RPath & rptNam & "_" & Date_export & ".rtf"
******

The date is not displayed in the field "exportlocation". I would appreciate
any help on this.

Thanks.
 
D

Douglas J. Steele

Variables declared in functions are not available outside of the function.

Private Function OfficeClosed(TheDate) As Date

' Test for Saturday or Sunday.
If Weekday(TheDate) = 2 Then
OfficeClosed = Date - 1
Else
OfficeClosed = Date
End If

End Function

To use:

exportlocation.Value = RPath & rptNam & "_" & OfficeClosed(Date) &
".rtf"


Incidentally, your comment says you're testing for Saturday or Sunday, but
in fact you're testing for Monday. Which is the error?
 
S

Shri

I am actually testing for Monday. The issue with the variable got resolved
but I got a new issue. I am not able to export the report to the location.
I get error mssg saying that "MS access can't save the output data to the
file you selected" .

The value to the export location is H:\Full Individual Audit_11/18/2008.rtf.

I appreciate your help.

Thanks.
 
S

Shri

I used below code to fix the issue with the variable.

exportlocation.Value = RPath & rptNam & "_" & OfficeClosed(Date) &
".rtf"
I formated the date to mm.dd.yyyy instead of '/' and I am able to export the
report.

Thanks to everyone for helping me with the issue.



tkelley via AccessMonster.com said:
For other's future benefit, how did you resolve your variable issue?

Regarding your report outupt, you cannot use "/" in a file name. Use dashes
or underscores.
I am actually testing for Monday. The issue with the variable got resolved
but I got a new issue. I am not able to export the report to the location.
I get error mssg saying that "MS access can't save the output data to the
file you selected" .

The value to the export location is H:\Full Individual Audit_11/18/2008.rtf.

I appreciate your help.

Thanks.
Variables declared in functions are not available outside of the function.
[quoted text clipped - 53 lines]
 
D

Douglas J. Steele

Yeah, sorry, I wasn't thinking that you were using the Date as part of a
filename.

You might be better off using:

Private Function OfficeClosed(TheDate As Date) As String

' Test for Monday
If Weekday(TheDate) = 2 Then
OfficeClosed = Format(Date - 1, "mm\_dd\_yyyy")
Else
OfficeClosed = Format(Date, "mm\_dd\_yyyy")
End If

End Function

and then use:

exportlocation.Value = RPath & rptNam & "_" & OfficeClosed(Date) &
".rtf"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top