Results 1 to 15 of 15
  1. #1
    yasso is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    11

    VBA Code not working to my Login Screen

    Hi,

    I have done small access database file with VBA Codes for my work including Login PopUp screen (username & Password) and also two Buttons (Login & Cancel). The issue is this login window is only working at my office computer and the weird thing is it will become unfunctional when I open it from my personnel computer. any body can advise?

    Gentlemen, just to let u know that my access file (login window) is working properly in all computers except my personnel laptop...!!!!!! pls advise.
    Last edited by yasso; 09-26-2020 at 02:15 PM.

  2. #2
    wvmitchell is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2020
    Posts
    24
    Is it possible that at the office, the user name includes the domain e.g. "DomainName\UserName" and at home it is "UserName"?

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    What does 'doesn't work' mean?? It runs but doesn't produce the desired result? It doesn't run at all? That's 2 entirely different things. If the latter, it is probably a Trusted Locations issue.

    P.S. please enclose code in code tags (# on forum toolbar) with proper indentation to make for easier reading.
    You could probably simplify that code with a simple DLookup to get the user name from the table. Opening a recordset for one value is not efficient.
    Last edited by Micron; 09-26-2020 at 10:41 AM. Reason: added info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    sID= Environ("Username")
    vPass = Dlookup("[Password]","tUsers","[UserID]='" & sID & "'")
    vRet = InputBox("Enter Password","Password")

    if vPass <> vRet then msgbox "Invalid"

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Might as well post what I was playing with in the last few minutes (maybe OP doesn't use Environ variables yet). Here's the original code approach but condensed
    Code:
    Private Sub btnLogin_Click()
    Dim strPassword As String
    
    strPassword = DLookup("Password","Users","username = '" & Me.txtUserName & "'")
    If Nz(strPassword,0) = 0 Or Me.txtPassword <> strPassword Then
      Me.lblIncorrectUserName.Visible = True
      Me.txtUserName.BorderColor = RGB(255, 0, 0)
      Exit Sub
    End If
    
    DoCmd.OpenForm "Home"
    DoCmd.Close acForm, Me.Name
    
    End Sub
    As long as the lookup won't error based on field/table names it should work, although an error handler wouldn't be a bad idea.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    yasso is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    11
    No it is not. The only thing I did that I took copy on USB Flash memory from office computer and tried to open it from home computer and unfortunately nothing happened!!!!!!

  7. #7
    yasso is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    11
    means, the pop up window for user name and password is there but there is no any functionality for both button (UserName / Password). it is working only from office computer and not home one.

  8. #8
    yasso is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    11
    means, the pop up window for user name and password is there but there is no any functionality for both button (UserName / Password). it is working only from office computer and not home one.

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    It sounds like the application is not being run from a trusted location. Can you see the yellow security banner with the Enable Content button? If so, click it.
    Also if you are trying to run the application from a USB drive, you risk corruption. I would copy it to your hard drive.

    One other thought. I your office PC running 32-bit Access & your home PC using 64-bit Access? If so, some API declarations may need tweaking to run correctly (though usually that would trigger an error message)
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  10. #10
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Quote Originally Posted by isladogs View Post

    ...if you are trying to run the application from a USB drive, you risk corruption. I would copy it to your hard drive...
    Also, be patient when doing the transfer. Flash drives sometimes pop up 'copy complete' message a second or two before the transfer is actually complete, and this, too, can cause corruption.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  11. #11
    yasso is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    11
    Quote Originally Posted by Missinglinq View Post
    Also, be patient when doing the transfer. Flash drives sometimes pop up 'copy complete' message a second or two before the transfer is actually complete, and this, too, can cause corruption.

    Linq ;0)>
    No use. Just giving same result. I am really frustrated. the same access file is working properly from office computer but it's not from my personnel one.!!!!!!!!!!!!!

  12. #12
    yasso is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    11
    I enabled already the content of yellow security banner. No Changes
    I copied the file to my hard disk. No Changes
    Yes, my Office computer is 32-bit and my home one is 64-bit.

  13. #13
    yasso is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    11
    Quote Originally Posted by isladogs View Post
    It sounds like the application is not being run from a trusted location. Can you see the yellow security banner with the Enable Content button? If so, click it.
    Also if you are trying to run the application from a USB drive, you risk corruption. I would copy it to your hard drive.

    One other thought. I your office PC running 32-bit Access & your home PC using 64-bit Access? If so, some API declarations may need tweaking to run correctly (though usually that would trigger an error message)
    I enabled already the content of yellow security banner. No Changes
    I copied the file to my hard disk. No Changes
    Yes, my Office computer is 32-bit and my home one is 64-bit.

  14. #14
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Enable the content again if need be, after opening the db. Then go to the module where this code is and put a break on it, then cause the login form to open/run. If the procedure runs, it will stop at your break point. Then step through it by pressing F8 each time it moves to a new code line. Watch what happens as you step through and you should be able to discover why it runs but doesn't perform as expected.

    If it doesn't run at all, then either it is usually a Trusted Locations issue - which you haven't commented on - or you have some other startup code or functionality that doesn't work as expected on your laptop. In that case, see if there are any AutoExec macros that aren't doing their thing (or startup form code). I can't recall if clicking to allow code to run is a one time thing or not because all my db's are OK in that respect. I can say that if an autoexec was supposed to run, then you allow code to run, it's too late for the autoexec or startup form that didn't run or open.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Also, check the references. Are any marked as MISSING?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. VBA code for login screen
    By JoeJr in forum Programming
    Replies: 2
    Last Post: 10-13-2019, 05:57 PM
  2. LogIn Screen
    By Bongobob21 in forum Forms
    Replies: 2
    Last Post: 05-18-2015, 08:28 AM
  3. Login form code not working
    By dharmacloud in forum Forms
    Replies: 11
    Last Post: 08-22-2011, 03:08 PM
  4. Login ID Code for Access 2007 not working
    By amangupts in forum Programming
    Replies: 25
    Last Post: 07-07-2011, 01:28 PM
  5. Login/Password Code not working
    By eww in forum Programming
    Replies: 3
    Last Post: 09-21-2010, 10:49 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