Strange Environ behaviour on a form

ianward

Registered User.
Local time
Today, 18:50
Joined
May 1, 2007
Messages
52
Hi all,

I have on a form a text box where the Default Value =Environ("Computername").

Now this has previously worked just fine, but for some reason for the last couple of times i have gone into the form the text is displayed as "#Name?" not the computer name which is expected.

...However if I type in the Immediate window
Code:
PRINT Environ("Computername")
The computer name text is displayed as it should be...

Has anyone any idea's on what is causing this glitch?

Many Thanks - Ian
 
Where exactly is this textbox on the form? Is this a bound textbox? A Default Value only appears when a record is first created, and if the value isn't saved to the underlying table, will have no source that Access can evaluate and could lead, I suppose, to this type of error.
 
Hi Missinglinq,

Yes in this instance the textbox is unbound, but i also use this in an append query to append to a logon table the date/time, Username, ComputerID & DbVersion, so that i know who has used the db on which pc and which Front End version they are using, this has worked on my machine but suddenly stopped working - and the FE works fine on other machines.
 
Well this has baffled me as to why it used to work on my machine but no longer does, and works fine on others... anyway as they say there is always more than one way to skin a cat, i found another piece of code for displaying usernames, which i thought i would give a try to see if i could display the computername... hey presto! - it works:

Code:
Function GetComputer() As String
Dim si As SystemInfo
Set si = New SystemInfo
Dim strOut As String
GetComputer = si.ComputerName
If GetComputer = "" Then
    MsgBox ("There is a problem with your Computer Name!! Please contact your Network Administrator.")
    DoCmd.Quit
End If
End Function

Regards - Ian
 
Glad you found a workaround! What version of Access are you running on the errant machine? While I've stayed away from v2007, I seem to remember something by Allen Browne to the effect that this version doesn't support Environ().
 
Hi Missinglinq,

I am using Access 2003, very strange - i am not aware of any updates etc that have been applied which may cause the variation... think I may just end up putting this down as "gremlins at work" however - at least the workaround is playing ball so far...

Regards - Ian
 
Gremlins do, indeed, lurk around the good kingdom of Access, from time to time, and cause much furor! Once again, glad you found a workaround. Allen Browne, and other heavy hitters in the Access world, preach against the use of Environ() for anything mission critical, because it can be diddled with so easily.
 

Users who are viewing this thread

Back
Top Bottom