By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

Module use?

P: 7
I'm attempting to create a login form to an access database. See code below. Login form has a ListBox (List10) and a text box (Text12). for users and passwords. List box created from KTCEMployees table and KTCEmployee is the index (hidden)


Expand|Select|Wrap|Line Numbers
  1. Private Sub Login_Click()
  2. On Error GoTo Err_Login_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "KTC Order Form"
  8.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  9.  
  10. Exit_Login_Click:
  11.     Exit Sub
  12.  
  13. Err_Login_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_Login_Click
  16.  
  17. End Sub
  18.  
  19. Private Sub List10_AfterUpdate()
  20. 'After selecting user name set focus to password field
  21.     Login.Text12.SetFocus
  22. End Sub
  23.  
  24. Private Sub Login1_Click()
  25. 'Check to see if data is entered into the password box
  26.     If IsNull(Login.Text12) Or Login.Text12 = "" Then
  27.         MsgBox "You Must Enter a password.", vbOKOnly, "Required Data"
  28.         Login.Text12.SetFocus
  29.         Exit Sub
  30.     End If
  31.  
  32. 'Check value of password in KTC Employees table to see if this
  33. ' matches value chosen in list box
  34.  
  35.     If Login.Text12.Value = DLookup("Password", "KTCEmployees", _
  36.                                     "[KTCEmployee]" & Login.List10.Value) Then
  37.         KTCEmployee = Login.List10.Value
  38.  
  39.         'Close login form and open Form menu
  40.  
  41.         DoCmd.Close acForm, "Login", acSaveNo
  42.         DoCmd.OpenForm "FormMenu"
  43.  
  44.     Else
  45.         MsgBox "Password Invalid.  Please try Again", vbOKOnly, "Invalid Entry!"
  46.         Login.Text12.SetFocus
  47.  
  48.     End If
  49.  
  50. End Sub
  51.  
I am supposed to create a module to declare variable such as:
Public KTCEmployee As Long

but I don't know how to do this and do you have to link it to the form?
Oct 30 '06 #1
Share this Question
Share on Google+
1 Reply


NeoPa
Expert Mod 15k+
P: 31,342
In Project window of VBA window, go to Modules in your Project and right-click.
Select Insert Module.
If you add the code
Expand|Select|Wrap|Line Numbers
  1. Public KTCEmployee As Long
then it will be visible across your project, including in Queries and Reports.
Oct 30 '06 #2

Post your reply

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