Environ() Object

adam.greer

Registered User.
Local time
Today, 12:32
Joined
Apr 27, 2006
Messages
43
Hi

I'm using Access 2003 and I came across the Environ function and it's exactly what I need.

I believe I am running in sandbox mode however I found this bit of code on the MS help

Code:
Public Function Environ(Expression)
Environ = VBA.Environ(Expression)
End Function



I also found Ghudson's post with the same code.

However when I try and use it I receive an error

Run-time error '424'

Object Required


I assumed this ment I was missing a reference. However after trawling the forums and google all I could find with the 'Visual Basic for Aplications'. Is that the correct Object, because I am alreayd using that in my DB.


I am calling the function like this

Code:
Private Sub Name_Click()

Forms_Form1.Name = Environ("Username")

End Sub


Any ideas?

Thanks
 
It's telling you Forms_Form1 doesn't exist. That's the "required object" in this case as you need to have something to assign a name to, and it can't find anything with the name you've provided.

I'm going to guess you've got a form named Form1 (the default name). The corrected syntax is:

Forms!Form1.Name = Environ("UserName")

I'm not sure you can change the name of a form while it's open (I don't think you can). If you're trying to set the caption, use the caption property instead.

Forms!Form1.Caption = Environ("UserName")
 
Last edited:
Alright you win this round Moniker ;)

But now I receive an error 2135

This property is read-only and can't be set.


Thought that was an odd one.
 
The name is read-only when the form is open. Set the caption property instead (which is what is displayed at the top of the form's window).

Forms!Form1.Caption = Environ("UserName")
 
No problem. Sometimes they're easy ones to nip in the bud. :)
 

Users who are viewing this thread

Back
Top Bottom