Results 1 to 11 of 11
  1. #1
    TheKillerMonkey is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    26

    Enabling buttons on new form from modal / Setting values in table

    Hello,



    I've built a user login form as a modal form and when you click the "OK" button it opens the "Home" Form which has 3 buttons, "Login Sheet", "Admin Functions" and "Syst. Man. Functions".

    For reference: System Manager = 1, Admin = 2, User = 3

    Order of "OK" macros: If User/Pass combo is good - open form home, disable buttons based on security, close user login form.


    It's the disabling of the buttons that is giving me an issue. Using the macro builder function, I've tried using an if IIF/DLookup combo to get the security and disable the "Home" buttons when the user clicks "OK", but I'm getting an error that the form for the buttons to disable doesn't exist.
    ___
    So my other thought (and something I'd like to have for future endeavors), would be to have a "Current User" table that stores the username that was logged in and its corresponding security level. However when I tried doing the setValue macro, I'm getting an error. (I can post a screenshot of what I'm working with tomorrow when I'll have the program in front of me). Essentially it was
    Code:
     Item: [CurrentUser]![Username], Expression: [tbUsername]
    One question I have with this, is it doesn't seem to take a value for an ID field, but basically the intent is to override this value on each new login so I don't want to create a table of all the users that have ever logged in...

    Thanks,
    -Matt

  2. #2
    TheKillerMonkey is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    26

    1st half

    Click image for larger version. 

Name:	UserLoginMacro.png 
Views:	19 
Size:	25.9 KB 
ID:	24324Click image for larger version. 

Name:	MacroErrorBtn.png 
Views:	19 
Size:	20.9 KB 
ID:	24325Click image for larger version. 

Name:	MacroErrorBtn2.png 
Views:	19 
Size:	21.1 KB 
ID:	24326

    These are what I'm seeing when I try to disable the buttons when they successfully log in. Text4 is my password field, Text2 is my username field.

  3. #3
    TheKillerMonkey is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    26

    2nd half

    Click image for larger version. 

Name:	SetValueMacro.png 
Views:	19 
Size:	3.2 KB 
ID:	24331Click image for larger version. 

Name:	SetValueError.png 
Views:	19 
Size:	14.1 KB 
ID:	24332Click image for larger version. 

Name:	SetValueError2.png 
Views:	18 
Size:	17.5 KB 
ID:	24333
    These are the errors I'm getting with the setValue macro... in the expression do I need a statement like where ID=1?

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I think this is a similar situation that has been answered in this post
    https://www.accessforums.net/showthread.php?t=59077
    See if you can grasp the concept and make use of it.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    TheKillerMonkey is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    26
    Similar, but their controls for enabling/disabling are a bit more complex than what I've got going on.

    btn1 is always enabled, btn2 if its admin/SystMan, btn3 only for SystMan
    I've found the CurrentUser() function returns the SecurityLevel value from my table... which for now is ok.

    Mine would essentially be 2 if statements.
    If CurrentUser() = 'Admin' then
    btn2.enabled=true
    else if CurrentUser() = 'SystMan' then
    btn2.enabled = true
    btn3.enabled = true
    end if

    I'm just unsure of syntax because access didn't like my If statement >.>
    Also tried building it in the macrobuilder for an On_Load event but it doesn't want to recognize the existence of my buttons. I've tried both Forms!Home!btn2 and [Forms]![Home]![btn2] and I keep getting the error message that it doesn't exist.

  6. #6
    TheKillerMonkey is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    26
    I'll probably update my program to take the environ username eventually... just for now I'm not sure what those values for the users would be/haven't taken the time to do the troubleshooting. I feel competent switching from the CurrentUser() to a DLookUp when I cross that bridge.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I think too many questions all at once, dealing with different things that may or may not be relevant. I'm having trouble sorting/following it all. Try using the code builder to see if you have the form and control names correct (I can't see that) or double check the spelling. If that's not it, for what it's worth, I do not use the ! between a form name and a control, rather Forms!Home.btn2. The ! denotes what follows is a member of a collection. Your text box does not have a collection of it's own. Of course, everything after that ! not only has to exist, it must exist as spelled.

    If I new what CurrentUser() was I could comment more on that as possibly being a problem or not.

  8. #8
    TheKillerMonkey is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    26
    Yea sorry about that... was getting ahead of myself as I'm trying to troubleshoot this...
    TestDB.accdb

    Changing Forms!Home!btn2 to Forms!Home.btn2 didn't fix the nonexistant button issue.

    Essentially what I was using CurrentUser() for was a substitute for DLookUp("[SecurityLevel]","Users","[Username]="&[tbUsername]).

    Attached is basically the current problem. I can login fine, but the second button should be enabled if the user is an Admin. (Matt/password) for textbox fields.
    Attached Files Attached Files

  9. #9
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    In an unsecured database, CurrentUser returns "Admin" so I suspect in your case it will never equal anything else. Forget that and use either the Environ or fosUserName functions (Google them for help). Do a DLookup to get the level from table "user" based on the logged in name that either of those two functions returns. You may not have a table field for this; it's likely that the login id the function will return and your user names are not the same.

    As for the db you posted, I cannot access the macro in my version. It seems there is something about it that is incompatible with 2007 version so I'm kind of limited as to what I can do with your version. Sorry.
    Last edited by Micron; 04-15-2016 at 05:18 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In the line
    Code:
    If (DLookup("[SecurityLevel]", "Users", "[User]='" & tbUserName & "'") = "Admin") Then
    there should be double quotes around ADMIN, not single quotes. The outermost parentheses are not needed

    I tried and tried to get the macro to set the enabled property of button2 but no joy. I really detest macros!
    I finally got the button to be enabled, BUT I had to convert the macro to VBA code and edit the code.
    Code:
    '------------------------------------------------------------
    ' Command4_Click
    '
    '------------------------------------------------------------
    Private Sub Command4_Click()
    On Error GoTo Command4_Click_Err
    
       If (DLookup("[Password]", "Users", "[User]='" & tbUserName & "'") = tbPass) Then
          If (DLookup("[SecurityLevel]", "Users", "[User]='" & tbUserName & "'") = "Admin") Then
             DoCmd.OpenForm "Home", acNormal
             Forms!Home!btn2.Enabled = True
          End If
       End If
    
    Command4_Click_Exit:
       Exit Sub
    
    Command4_Click_Err:
       MsgBox Error$
       Resume Command4_Click_Exit
    
    End Sub
    **You really should take the time to give meaningful names to your objects.

  11. #11
    TheKillerMonkey is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    26
    I don't mind macro builders if they actually do the job that their name entails... The interface can allow for someone not as versed with code/syntax to use the program. Granted with the way access is set up, you have to commit to either builder or code, and I can see why its easier/simpler to just stick to code.

    I give meaningful (or at least meaningful to me) names to objects that mean something to the program/need to be referenced by a line of code.

    I appreciate the support

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2014, 12:19 PM
  2. Replies: 4
    Last Post: 10-25-2013, 06:48 AM
  3. Enabling controls on a form
    By crowegreg in forum Programming
    Replies: 4
    Last Post: 08-22-2013, 09:18 AM
  4. Replies: 1
    Last Post: 03-29-2011, 11:05 AM
  5. Enabling Disabling Combo Boxes from Values
    By vdanelia in forum Forms
    Replies: 3
    Last Post: 02-04-2011, 10:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums