UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Set Edit Button Visible Depends On Created User Name, Access 2010    
 
   
Alhakeem1977
post Aug 18 2017, 03:41 AM
Post#1



Posts: 64
Joined: 8-July 17



I have got MS Access form with Edit button called cmdEdit.
I want to allow this button to be visible depends on the same user how created it, it will identify the user by code called Environ ("UserName")set as text field called txtUseID, with Dlookup function I have this VBA code in On Current event but it not working I got a Run-time error '94'.
I prefer if any body have something better.
CODE
   Private Sub Form_Current()
Dim Security As Integer

Me.txtUserID = Environ("Username")
Me.txtUserName = DLookup("UserName", "tblUser", "[UserLogin]='" & Me.txtUserID & "'")

If IsNull(DLookup("UserSecurity", "tblUser", "[UserLogin] = '" & Me.txtSenderID & "'")) Then
    Security = DLookup("Usersecurity", "tblUser", "[UserLogin] = '" & Me.txtSenderID & "'")
    Select Case Security
    Case 1
        Me.cmdEdit.Enabled = True
End Select
End If


Thanks in advance

--------------------
Best Regards,

Al Hakeem1977
Go to the top of the page
 
ScottGem
post Aug 18 2017, 06:32 AM
Post#2


UtterAccess VIP / UA Clown
Posts: 32,183
Joined: 21-January 04
From: LI, NY


Wow a lot of code for a simple task:

CODE
Me.cmdEnabled = (Me.txtSenderID = Environ("Username"))


This will suffice if the SenderID is equal to the Current user. If they also have to have a security level of 1 then use:

CODE
If Nz(DLookup("Usersecurity", "tblUser", "[UserLogin] = '" & Environ("Username") & "'"),0) = 1 then
     Me.cmdEdit.Enabled = True
End If

--------------------
Scott <>
Scottgem's Blog
Microsoft Access MVP since 2007
Author: Microsoft Office Access 2007 VBA
Go to the top of the page
 
Alhakeem1977
post Aug 18 2017, 10:15 AM
Post#3



Posts: 64
Joined: 8-July 17



Thanks for your kind reply, Actually I am new at Access.
I will try the code later because I'm not at home for sure it will work.

I've got another issue in another form that when the user click a check box called (Received) it will populate another text field with the Environ ("UserName") called txtUserID it works perfect but the problem is that when the user clicked it accidentally and un clicked it will not erase the user name from the table.
How can I set the code for this issue? In which event procedure I have to put it? In the form property or (Received) property?

Thanks a lot in advance.

--------------------
Best Regards,

Al Hakeem1977
Go to the top of the page
 
Alhakeem1977
post Aug 18 2017, 11:52 AM
Post#4



Posts: 64
Joined: 8-July 17



One more thing please, what code I have to put in the form text field to show or count the number of un received documents ( un clicked received check box ) .
Thanks a lot

--------------------
Best Regards,

Al Hakeem1977
Go to the top of the page
 
Alhakeem1977
post Aug 18 2017, 01:09 PM
Post#5



Posts: 64
Joined: 8-July 17



1

--------------------
Best Regards,

Al Hakeem1977
Go to the top of the page
 
ScottGem
post Aug 19 2017, 07:52 AM
Post#6


UtterAccess VIP / UA Clown
Posts: 32,183
Joined: 21-January 04
From: LI, NY


For future reference, if you have new, unrelated questions, please start a new thread for them. Also, if you have a question about code not working please post the code.

For the checkbox.I would use the After Update event

CODE
If Me.Received Then
    Me.txtUserID = Environ("Username")
Else
    Me.txtUserID = Null
End If


Checkout the DCount function

--------------------
Scott <>
Scottgem's Blog
Microsoft Access MVP since 2007
Author: Microsoft Office Access 2007 VBA
Go to the top of the page
 
Alhakeem1977
post Aug 19 2017, 10:49 PM
Post#7



Posts: 64
Joined: 8-July 17



Thanks a lot it works perfectly. hat_tip.gif thanks.gif

--------------------
Best Regards,

Al Hakeem1977
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    17th December 2017 - 03:16 AM