473,378 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

ms access vba code

8
Pls i use a vba code in ms access to login into my form. but i want if student login it should bring out such student record. pls what are my going to add to the below code to enable each student to login into their form. thank you.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Private Sub Command1_Click()
  3. Dim User As String
  4. Dim UserLevel As Integer
  5. Dim TempPass As String
  6. Dim ID As Integer
  7. Dim UserName As String
  8. Dim TempID As String
  9. If IsNull(Me.txtUserName) Then
  10.  MsgBox "Please enter UserName", vb
  11.  Me.txtUserName.SetFocus
  12. ElseIf IsNull(Me.txtPassword) Then
  13.  MsgBox "Please enter Password", vb
  14.  Me.txtPassword.SetFocus
  15. Else
  16.  If (IsNull(DLookup("UserLogin", "t
  17.  MsgBox "Invalid Username or Passwo
  18.  Else
  19.  TempID = Me.txtUserName.Value
  20.  UserName = DLookup("[UserName]", "
  21.  UserLevel = DLookup("[UserType]",
  22.  TempPass = DLookup("[UserPassword]
  23.  UserLogin = DLookup("[UserLogin]",
  24.  DoCmd.Close
  25.  If (TempPass = "password") Then
  26.  MsgBox "Please change Password", v
  27.  DoCmd.OpenForm "frmUserinfo", , ,
  28.  Else
  29.  'open different form according to
  30.  If UserLevel = 1 Then ' for admin
  31.  DoCmd.OpenForm "Admin Form"
  32.  Else
  33.  DoCmd.OpenForm "Navigation Form"
  34.  End If
  35.  End If
  36.  End If
  37. End If
  38. End Sub
  39. Private Sub Form_Load()
  40. Me.txtUserName.SetFocus
  41. End Sub
Aug 1 '17 #1
6 3456
ADezii
8,834 Expert 8TB
Much of your Code is truncated, please repost the Code in its entirety.
Aug 5 '17 #2
aym2u2
8
@ADezii
ok tnx for ur respond i will do that
Aug 11 '17 #3
aym2u2
8
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Command1_Click()
  4. Dim User As String
  5. Dim UserLevel As Integer
  6. Dim TempPass As String
  7. Dim ID As Integer
  8. Dim UserName As String
  9. Dim TempID As String
  10.  
  11. If IsNull(Me.txtUserName) Then
  12.  MsgBox "Please enter UserName", vbInformation, "Username required"
  13.  Me.txtUserName.SetFocus
  14. ElseIf IsNull(Me.txtPassword) Then
  15.  MsgBox "Please enter Password", vbInformation, "Password required"
  16.  Me.txtPassword.SetFocus
  17. Else
  18.  If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin = '" & Me.txtUserName.Value & "' And UserPassword = '" & Me.txtPassword.Value & "'"))) Then
  19.  MsgBox "Invalid Username or Password!"
  20.  Else
  21.  TempID = Me.txtUserName.Value
  22.  UserName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
  23.  UserLevel = DLookup("[UserType]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
  24.  TempPass = DLookup("[UserPassword]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
  25.  UserLogin = DLookup("[UserLogin]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
  26.  DoCmd.Close
  27.  If (TempPass = "password") Then
  28.  MsgBox "Please change Password", vbInformation, "New password required"
  29.  DoCmd.OpenForm "frmUserinfo", , , "[UserLogin] = " & UserLogin
  30.  Else
  31.  'open different form according to user level
  32.  If UserLevel = 1 Then ' for admin
  33.  DoCmd.OpenForm "Admin Form"
  34.  Else
  35.  DoCmd.OpenForm "Navigation Form"
  36.  End If
  37.  
  38.  End If
  39.  End If
  40. End If
  41. End Sub
  42.  
  43. Private Sub Form_Load()
  44. Me.txtUserName.SetFocus
  45. End Sub
Aug 11 '17 #4
NeoPa
32,556 Expert Mod 16PB
@Aym2u2.

I've just sent you a PM. Please read it and confirm receipt by clicking on the box.

I omitted to include an injunction to express yourself in proper English where possible. Txtspk is fine for phones but not acceptable here. It's harder to understand and annoying for most who try to read it. Not everyone here is even familiar with it. Many of those that are find it irritating. Our rules prohibit its use explicitly.

PS. Just to be absolutely clear, this is not about how well you speak and understand English. We have no problem with people trying to communicate in English and just not being very good. This is about the unnecessarily abbreviated nature of writing Pls instead of Please; ur instead of you're or you are; etc.

Clearly you are a polite person. I can see that. Also you aren't aware of all our rules so I'm explaining some of them for you in order that you don't upset people and you get more people willing to offer you help.
Aug 12 '17 #5
NeoPa
32,556 Expert Mod 16PB
I believe you mentioned elsewhere that you're new to Access and VBA. In that case one of the most helpful tips I can give you is to ensure all variables are properly declared (Require Variable Declaration). This will save you a great deal of unnecessary grief.
Aug 12 '17 #6
aym2u2
8
Firstly, I Create a table tblUser with a UserName, UserLogin, UserSecurity and UserPassword fields. and tblSecurity with SecurityID and SecurityLvl.

Secondly i have a form with ID, FirstName, MiddleName, LastName, Country etc.

So Using the BELOW code only open Form with ID 1, assuming my userLogin is aym2u2, my Password is 1234 and is on ID. 5 in the tblUser what are my going to do to open Form corresponding to ID 5.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Command1_Click()
  4. Dim User As String
  5. Dim UserLevel As Integer
  6. Dim TempPass As String
  7. Dim ID As Integer
  8. Dim UserName As String
  9. Dim TempID As String
  10.  
  11.  
  12. If IsNull(Me.txtUserName) Then
  13.  MsgBox "Please enter UserName", vbInformation, "Username required"
  14.  Me.txtUserName.SetFocus
  15. ElseIf IsNull(Me.txtPassword) Then
  16.  MsgBox "Please enter Password", vbInformation, "Password required"
  17.  Me.txtPassword.SetFocus
  18. Else
  19.  If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin = '" & Me.txtUserName.Value & "' And UserPassword = '" & Me.txtPassword.Value & "'"))) Then
  20.  MsgBox "Invalid Username or Password!"
  21.  Else
  22.  TempID = Me.txtUserName.Value
  23.  UserName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
  24.  UserLevel = DLookup("[UserType]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
  25.  TempPass = DLookup("[UserPassword]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
  26.  UserLogin = DLookup("[UserLogin]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
  27.  DoCmd.Close
  28.  If (TempPass = "password") Then
  29.  MsgBox "Please change Password", vbInformation, "New password required"
  30.  DoCmd.OpenForm "frmUserinfo", , , "[UserLogin] = " & UserLogin
  31.  Else
  32.  'open different form according to user level
  33.  If UserLevel = 1 Then ' for admin
  34.  DoCmd.OpenForm "Admin Form"
  35.  Else
  36.  DoCmd.OpenForm "Navigation Form"
  37.  End If
  38.  
  39.  End If
  40.  End If
  41. End If
  42. End Sub
  43.  
  44. Private Sub Form_Load()
  45. Me.txtUserName.SetFocus
  46. End Sub
Aug 16 '17 #7
NeoPa
32,556 Expert Mod 16PB
Clearly you have no worries about saving yourself unnecessary grief as per my last post. Let me see if I can explain it another way. When experts see code posted without that important line at the top (Option Explicit), as explained in the linked article, they will do one of two things :
  1. Advise you that it's very unwise to do anything with such code.
  2. Assume you're beyond help and ignore your posts.

So. Not only is it wise to do for your own sake and sanity, it will also increase your chances of anyone bothering to help you when you post.

Ultimately though, it's entirely your call. You have all the relevant information available to you so you can take full responsibility for your choice.
Aug 16 '17 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Robin Lewis | last post by:
I have a simple Access database set up and a form and I need to compare two textboxes, 'email1' and 'email2', on the form. If the two textboxes do NOT match I need to change the background colour...
1
by: nickel | last post by:
I can access Microsoft Access database via ODBC on Windows 2000 using C++. Now, I would like to use the SAME piece of code to access MS SQL on Windows. Can I achieve this without any modification...
2
by: nickel | last post by:
I can access Microsoft Access database via ODBC on windows 2000 using C++ . Now, I would like to use the SAME piece of code to access MS SQL on Windows. Can I achieve this without any...
1
by: Rocky A | last post by:
I need to open an excel workbook and import info to my access program. That isn't the problem, I've got the code down for doing what I want to do. I'm declaring the variable and setting it like...
4
by: hendafe | last post by:
I have a problem of removing '/' in Access. I have a field with this record BD/02/1234. I want to automatically remove the '/' and save it in a new field record for another purpose. Presently...
6
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. ...
2
by: Vinayak Raghuvamshi | last post by:
I have a file that has been created using shared read/write access. But C# code never is able to open this file for read and keeps throwing "...cannot open file as it is being used by another...
10
by: Stefan Weber | last post by:
Hi, I'm trying to access the JavaScript code contained in a <scripttag via its "text" attribute. This works well, if the code is embedded in the HTML page. However, when the code is in an...
1
by: BhupendraNVyas | last post by:
Dear All, I want to send Out standing E-Mail detail to customer's throug ms access code .....can you help me for genrate a mail and attach a file from local hard disk drive. Regards, Bhupendra
0
by: group014 | last post by:
1. Groups provide members who purchase a course a voucher with an access code. 2. Buyer enters his unique, personal access code in our site to access registration page. 3. Once registered he has...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.