Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Variable defined in a function

Geek News

Variable defined in a function
Shri 11/19/2008 5:22:16 PM
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.

Re: Variable defined in a function
"tkelley via AccessMonster.com" <u47368[ at ]uwe> 11/19/2008 5:32:48 PM
You're declaring your private variable in your private function. Doesn't
your Date_Export variable lose it's scope outside of the function? I think
for the way you have written it, you should declare your Date_Export variable
as public at the top of the form.

Try that and see if it doesn't work.


Shri wrote:
[Quoted Text]
>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.

--
Message posted via http://www.accessmonster.com

Re: Variable defined in a function
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_gmail.com> 11/19/2008 5:36:46 PM
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?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Shri" <Shri[ at ]discussions.microsoft.com> wrote in message
news:6F639091-2638-42F8-AE66-3B2569C226B6[ at ]microsoft.com...
[Quoted Text]
> 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.
>


Re: Variable defined in a function
Shri 11/19/2008 7:24:05 PM
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.

"Douglas J. Steele" wrote:

[Quoted Text]
> 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?
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Shri" <Shri[ at ]discussions.microsoft.com> wrote in message
> news:6F639091-2638-42F8-AE66-3B2569C226B6[ at ]microsoft.com...
> > 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.
> >
>
>
>
Re: Variable defined in a function
"tkelley via AccessMonster.com" <u47368[ at ]uwe> 11/19/2008 7:29:05 PM
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.

Shri wrote:
[Quoted Text]
>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]
>> >
>> > Thanks.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200811/1

Re: Variable defined in a function
Shri 11/19/2008 7:47:01 PM
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" wrote:

[Quoted Text]
> 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.
>
> Shri wrote:
> >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]
> >> >
> >> > Thanks.
>
> --
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200811/1
>
>
Re: Variable defined in a function
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_gmail.com> 11/19/2008 8:55:17 PM
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"


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Shri" <Shri[ at ]discussions.microsoft.com> wrote in message
news:28FD1EBB-1621-4233-B35A-44D800E017C2[ at ]microsoft.com...
[Quoted Text]
>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.
>
> "Douglas J. Steele" wrote:
>
>> 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?
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "Shri" <Shri[ at ]discussions.microsoft.com> wrote in message
>> news:6F639091-2638-42F8-AE66-3B2569C226B6[ at ]microsoft.com...
>> > 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.
>> >
>>
>>
>>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net