Hi All,
I want to turn some tabs on or off depending on which user is logged in. Is this possible?
Thanks,
Mark
Tab Control - Turn Tabs ON/OFF using VBA
-
- 3StarLounger
- Posts: 253
- Joined: 19 Apr 2010, 09:01
- Location: Indiana, USA
Tab Control - Turn Tabs ON/OFF using VBA
Thanks,
Mark
Mark
-
- 3StarLounger
- Posts: 253
- Joined: 19 Apr 2010, 09:01
- Location: Indiana, USA
Re: Tab Control - Turn Tabs ON/OFF using VBA
Hey, I found out by poking around!
Something like this! Where the .pages(x) is the index number of the tab control.
Me.TabCtl18.Pages(2).Visible = True
Thanks,
Mark
Something like this! Where the .pages(x) is the index number of the tab control.
Me.TabCtl18.Pages(2).Visible = True
Thanks,
Mark
Thanks,
Mark
Mark
-
- Administrator
- Posts: 78447
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Tab Control - Turn Tabs ON/OFF using VBA
If you mean the Windows username:
Copy the following code into a standard module:
The GetUser function returns the Windows username of the active user.
Create an On Load event procedure similar to the following for your form:
where Page1 etc. are the names of the tab pages.
Copy the following code into a standard module:
Code: Select all
Private Declare Function WNetGetUserA Lib "mpr.dll" _
(ByVal lpszLocalName As String, ByVal lpszUserName As String, lpcchBuffer As Long) As Long
Public Function GetUser() As String
Dim lpUserName As String, lpnLength As Long, lResult As Long
'Create a buffer
lpUserName = String(256, Chr$(0))
'Get the network user
lResult = WNetGetUserA(vbNullString, lpUserName, 256)
If lResult = 0 Then
GetUser = Left$(lpUserName, InStr(1, lpUserName, Chr$(0)) - 1)
Else
GetUser = "-unknown-"
End If
End Function
Create an On Load event procedure similar to the following for your form:
Code: Select all
Private Sub Form_Load()
Select Case GetUser
Case "HansV"
Me.Page1.Visible = False
Me.Page4.Visible = False
Case "SantosM"
Me.Page2.Visible = False
Me.Page3.Visible = False
Case Else
Me.Page4.Visible = False
End Select
End Sub
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 253
- Joined: 19 Apr 2010, 09:01
- Location: Indiana, USA
Re: Tab Control - Turn Tabs ON/OFF using VBA
Hi Hans,
Thanks! I may use that later, but for now I set a variable based on user location and will use that.
Thanks,
Mark
Thanks! I may use that later, but for now I set a variable based on user location and will use that.
Thanks,
Mark
Thanks,
Mark
Mark
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Tab Control - Turn Tabs ON/OFF using VBA
Environ$("Username") also returns the windows user name
-
- Administrator
- Posts: 78447
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Tab Control - Turn Tabs ON/OFF using VBA
That is true, but environment variables can easily be changed by the user, so a user could pretend to be someone else.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Tab Control - Turn Tabs ON/OFF using VBA
I didn't know that, thank you