Ms Access Login form and User Level

Anonymous
2021-04-17T02:19:13+00:00

I am trying to make Login Form Using DCount and LookUp functions 

My table has the following field LoginID, UserName, Password, Level and Description

Form has:

Combobox Named: "txtUser" bound column is 1 (LoginID) and I hide it by sitting Column Widths by 0

TextBox Named "txtPass"

Login Button and I use If function with AND but it does not work, access alway open the main form to me he did not use "else"

  1. I want to say If txtUser and txtPass Mach then, show me message said Successfully, Close Login Form, Open the Main Form, else show me message said Failed, but access does not match "AND" he always open the Main form even If I put wrong password

If

I did this DCount("LoginID","LoginT","UserName=[txtUser]" And "Password=[txtPass]")

I did this DCount("LoginID","LoginT","UserNamer=[txtPass]") And ("Password","LoginT","Password=[txtPass]")

I did this DCount("LoginID","LoginT","UserNamer=[txtPass]" And "Password","LoginT","Password=[txtPass]")

I did this DCount("Password","LoginT","Password=[txtPass]")

they did not work

  1. How can I add Level deal with Levels by LookUp?

if the txtUser and txtPass Mach and his Level is 1 as admin open the Main form as edit, else as Read only

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

17 answers

Sort by: Most helpful
  1. Anonymous
    2021-04-17T03:34:17+00:00

    Hi ssd, I'm an independent adviser and will try to help.

    Frankly you are doing it the hard way. I've written a blog which describes how to do this. You can find it at https://scottgem.wordpress.com/2010/01/12/creat...

    This link is to a page on my website. It is safe. I am providing it because I think it contains information that will help you. However, as an Independent Advisor I am required to add this when posting here with a link to any non-Microsoft site.

    The code you are showing is incomplete and inefficient.

    If you need further clarification on this feel free to ask.

    3 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2021-04-17T03:44:46+00:00

    I want to use Macro because my VBA is blocked from my organization

    If u can help how to do login Form from Macro I will be apricaited

    Thanks

    0 comments No comments
  3. Anonymous
    2021-04-17T05:33:15+00:00

    Just for starters, your expression 

     DCount("LoginID","LoginT","UserName=[txtUser]" And "Password=[txtPass]")

    will not work, for two reasons: the word AND must be part of the expression, and since the fields are of TEXT datatype the criteria must be surrounded by quotemarks. Since the User name might contain a singlequote (O'Brian for example) I'd use doublequotes ". To include a " literal character in a " delimited string, double the doublequote (how's that for doubletalk!): try

     DCount("LoginID","LoginT","[UserName]=""" & [txtUser] & " AND [Password]=""" & [txtPass] & """")

    This will evaluate to 

    [UserName] = "O'Brian" AND [Password] = "QD123"

    Similarly for the other expressions.

    That said, unfortunately due to the  limitations of Macros and the generally weak security of Access, this security is about on the level of a $1.95 bicycle lock. It will inconvenience and briefly delay honest people, but can be hacked in minutes by anyone with a modicum of knowledge about Access. Scott's link will be much more useful; and your management's distaste for VBA is misguided and counterproductive.

    0 comments No comments
  4. Anonymous
    2021-04-17T08:18:51+00:00

    All the more reason to use the method I suggest in my blog. By using a Combobox to select the user, it makes it easier to use the Column property of the combobox to select values. You only need to use an IF to test the password. It becomes a simple macro.

    0 comments No comments
  5. Anonymous
    2021-04-17T17:23:29+00:00

    Thanks for trying  to help me, but I got this small error

    If I put the UserName his ID is 1 and his password is 123 I got this message

    kindly help me

    0 comments No comments