Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Username Table - How to use it using VBA

Status
Not open for further replies.

SERT1

Programmer
Sep 13, 2001
33
0
0
CA
I have created a username table in my database based on a network login. I have created VBA code that is supposed to look up the login ID in a table, but it's not working properly. Can anyone give me a code that will look up the "Environ("Username") and compare it with a table and either log into a program or quit?
 
Code:
Function IsValidUser() As Boolean
  Dim strUser As String
  Dim rst As Recordset
  Dim db As Database
  
  Set db = CurrentDb()
  
  Set rst = db.OpenRecordset("UserTable", dbOpenTable)
  
  strUser = Environ("username")
  
  With rst
    While Not .EOF
      If .Fields("UserID") = strUser Then
        IsValidUser = True
        GoTo ExitHere
      End If
      .MoveNext
    Wend
  End With
  
ExitHere:
  On Error Resume Next
  rst.Close
  Set rst = Nothing
  Set db = Nothing
End Function
VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top