first time use recordset :s help please

vinzz

Registered User.
Local time
Today, 03:25
Joined
Apr 24, 2008
Messages
47
hello,

I'm trying to make a vba script to check if a user has access.
i have a table called Vaststellers where the username is stored in the first column "gebruiker" and a second as Yes/No box if the user is marked as active. there is more data in this table but for the moment i only need those two.

now what i'm trying to accomplish is that when a user is not in this table or is in it but not active is true the program has to quit.

this is the code i've trying to make, with a search on this board. but it won't work :( :

NaamGebruiker: This is a module with a function called NaamGebruiker(). It gives the current username of the machine working on.
Code:
Private Sub Form_Open(Cancel As Integer)
    Dim db As Database
    Dim Lrs As DAO.Recordset
    Dim LSQL As String
    
    User = NaamGebruiker
    
    'Open connection to current Access database
    Set db = CurrentDb()

    'Create SQL statement to retrieve value from GST table
    LSQL = "SELECT Vaststellers.Gebruiker, Vaststellers.Actief FROM Vaststellers WHERE (((Vaststellers.Gebruiker)=User) AND ((Vaststellers.Actief)=True));"

    Set Lrs = db.OpenRecordset(LSQL)

    'Retrieve value if data is found
    If Lrs.EOF = False Then
    exit sub
    Else
    MsgBox "U hebt geen toegang tot deze database", vbCritical, "Geen toegang " & User
        
    End If

    Lrs.Close
    Set Lrs = Nothing
End Sub

Can someone tell me what i'm doing wrong and how to fix my problem? :s
 
Try

LSQL = "SELECT Vaststellers.Gebruiker, Vaststellers.Actief FROM Vaststellers WHERE Vaststellers.Gebruiker='" & User & "' AND Vaststellers.Actief=True;"
 
yep, it works now, thanks pbaldy!
 

Users who are viewing this thread

Back
Top Bottom