Compile Error using Environ("username")

cstickman

Registered User.
Local time
Today, 09:41
Joined
Nov 10, 2014
Messages
109
Hey Everyone,

So I have Access 2013 32Bit and the majority of my team has 2010. Recently they have been seeing an compile error on one of the forms. Below is the code and it highlights Me.txtuser = Environ("username") - All the code is doing is just looking up the name of the user and stating good morning, good afternoon or good evening.

one thing to mention is this is in a navigation form and everything was working perfectly until I went in and added more pages. I also have 4 user levels. So I am not sure if changing that code or adding the pages made a difference.

Code:
 Private Sub Form_Load()
Me.txtuser = Environ("username")
Me.txtname = DLookup("username", "tbluser", "[racfid] ='" & Me.txtuser & "'")
Me.txtgreeting = MyGreeting(txttime)
Me.txtwelcome = Me.txtgreeting & " " & Me.txtname
Me.txtuser.Visible = False
Me.txtname.Visible = False
Me.txtgreeting.Visible = False
Me.txttime.Visible = False
End Sub

**EDIT**
One thing to mention is that I changed the form that loaded on start up to just this greeting page and removed it from the navigation form.
 
RacfID is probly a number. You have it text in the DLOOKUP.
 
I suggest making sure the form still has the textbox with the name txtuser. The compile will stop on the first error it finds so I'd check the form for the other textboxes too.
 
Why even bother having the text box txtUserName . Replace the first two lines with
Me.txtname = DLookup("username", "tbluser", "[racfid] ='" & Environ("username") & "'")This is of course if the user logon names are stored in the field 'racfid' in table tblUser
 
Hey guys so we came across what the issue was with the code. I am using Access 2013 and the users were on 2010. The object library for me was at 15 and the users had 14. So the reason why an older version of the database worked was because it was written in 2010, but when changes were made and saved with 2013 it changed the object library to 15. I tried to reference both 14 & 15 in code, but every time you made a save it deleted the 14.
 
Compiler errors will often originate from broken references OR obsolete references if the syntax is otherwise right. Therefore, verify all references are current. I'm saying it that way because on some versions of Windows you can have multiple versions of Office coexist, and that can sometimes lead to inconsistent references. That behavior of changing from 14 to 15 is not one I've seen before but it doesn't surprise me at all.

Compiler errors will ALSO originate from variable-name spelling errors if you have Option Explicit in your VBA code headers. However, you have indicated that it was a references problem, so just file my comments for future speed-bumps along the road.
 

Users who are viewing this thread

Back
Top Bottom