Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim wshNet
Dim sUser As String
Set wshNet = CreateObject("WScript.Netw
conn.ConnectionString = "Provider=Microsoft.Jet.OL
conn.Open
sqlstr = "Table"
rs.Open sqlstr, conn, adOpenKeyset, adLockOptimistic
cmdbutton1.Visible = False
cmdbutton2.Visible = False
With rs
Do Until .EOF or found
If .Fields("UserName") = wshNet.UserName Then
IF .Fields("ButtonAccess1") = 1 Then
cmdbutton1.Visible = True
End IF
IF .Fields("ButtonAccess2") = 1 Then
cmdbutton2.Visible = True
End IF
End IF
Loop
End With
Set wshNet = Nothing
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
End Sub
Main Topics
Browse All Topics





by: g0rathPosted on 2004-12-15 at 10:49:00ID: 12833224
To get login name:
/library/d efault.asp ?url=/libr ary/ en-us/ his_2004Ma in/htm/ his _dg_dataac cesslibrar y_guide_su btopics_fd rs.asp
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Public Function UserName() As String
Dim llReturn As Long
Dim lsUserName As String
Dim lsBuffer As String
lsUserName = ""
lsBuffer = Space$(32)
llReturn = GetUserName(lsBuffer, 32)
If llReturn Then
lsUserName = UCase$(Left$(lsBuffer, InStr(lsBuffer, Chr(0)) - 1))
End If
UserName = lsUserName
Exit Function
End Function
'Use ADO to connect to the SQL server
Dim cnn as ADODB.Connection
Dim rs as ADODB.RecordSet
Set cnn = New ADODB.Connection
cnn.ConnectionString = 'whatever connection string it takes to connect to your sql server, access db or whatever
'If you know nothing about connection strings, look at this example
'http://msdn.microsoft.com
Set rs = cnn.Execute "SELECT Button1 FROM ExampleTable WHERE UserName = " & UserName()
If not isObject(rs) then goto ErrHandler
If rs.eof = true then goto ErrHandler
If rs.fields(0).value = 1 then
Button1.Visible = true
else
Button1.Visible = false
end if
rs.close
set rs = nothing
set cnn = nothing