Help needed on LOGON Module

mosh

Registered User.
Local time
Today, 23:31
Joined
Aug 22, 2005
Messages
133
Hi All,

I have the following module that basically looks at the table and if the user does not exist (the workstation LANID) then it asks the user to create a new logon for that user. But how can i also ask the user to enter other details such as forename, surname, DOB and sav it to the table also?

Function LanCheck()
Dim Lan, Emp As String
Lan = GetWorkstationLan

Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("Select * from tblStaff where Employee_Lan = '" & Lan & "';")
If rs.RecordCount = 0 Then
Emp = InputBox("Please Enter Your Name as You have not got an account.",)
If Emp = "" Then
MsgBox "You did not enter a name!!!"
DoCmd.Quit
End If

With rs
.AddNew
!employee_name = Emp
!employee_lan = Lan
.Update
End With
End If
End Function

Thanks
________
Sweetcutepussy25
 
Last edited:
Let's say the Form that is calling the LanCheck Function below is named "frmStartUp".

Add another Form to your DB that allows a new User to add the required details. Let's call it "frmAddUser". Bind this Form to the Table named "tblStaff" and the Controls on this Form their respective Table Fields. Use the MS-Access Form Wizard to quickly make this for you if you don't already have one.

Code:
Function LanCheck() As Boolean
   [COLOR="DarkGreen"]'Declare Variables...[/COLOR]
   Dim Lan
   
   [COLOR="DarkGreen"]'Get the Lan ID from the GetWorkstationLan Function[/COLOR]
   Lan = GetWorkstationLan
   
   [COLOR="DarkGreen"]'See if the Lan ID is within the tblStaff Table.[/COLOR]
   If Nz(DLookup("[Employee_Name]", "[tblStaff]", "[Employee_Lan]='" & Lan & "'"), "") = "" Then
      [COLOR="DarkGreen"]'Nope, its not...Inform the User. If the User selects anything
      'other than YES then the application closes.[/COLOR]
      If MsgBox("Your Work-Station can not be found in our list." & vbcr & _
                "Would you like to join the Clik?", VbQuestion + vbYesNo, _
                "Join The Clik") <> vbYes Then DoCmd.Quit
      End if

      [COLOR="DarkGreen"]'The User want to Add themselves to the Staff list so open the
      'frmAddUser Form to allow him/her to do so. Because the Form is
      'opened in Dialog mode, the code following will not run until
      'the frmAddUser Form is closed.[/COLOR]      
      DoCmd.OpenForm "AddUser", acNormal, , , acFormAdd, acDialog, "frmStartUp"

      [COLOR="DarkGreen"]'Well, the frmAddUser Form is closed now. Was something placed into the
      'frmStartUp Form (this Form) Tag property?
      'I quess not so quit the application.[/COLOR]
      If Me.Tag = "" then DoCmd.Quit

      [COLOR="DarkGreen"]'Hmmm...the above condition wasn't met so I guess the frmAddUser Form
      'was properly filled in. Let's welcome the new User.[/COLOR]
      MsgBox "Welcome " & Me.Tag & " to the CLIK. We hope you enjoy your....whatever.", _
                      vbInformation, "Welcome " & Me.Tag

      [COLOR="DarkGreen"]'Clear the frmStartUp Form's Tag property. We don't
      'need it anymore and we certainly don't want it to 
      'retain a name from a previously joined individual.[/COLOR]
      Me.Tag = "" 

      [COLOR="DarkGreen"]'Set this Function to return TRUE since we have success.  :)[/COLOR]
      LanCheck = True
   End If
End Function

Within the frmAddUser Form's OnUnload event, check the condition of all Form data entry Fields to ensure they have all been filled in. If it is proven that all fields are filled then check to see if the frmStartup Form's Name was passed by way of the frmAddUser Form's OpenArgs property. If there is then set the Tag property of the frmStartUp Form to the Name entered by the User. If the User decided to say "the heck with it" and just closed the frmAddUser Form then nothing is placed into the frmStartUp Form's Tag property. This is later detected and the application closes.

Your frmAddUser Form's OnUnload event should look something like this:

Code:
Private Sub Form_Unload(Cancel As Integer)
   [COLOR="DarkGreen"]'If the Form hasn't been touched then just close and leave.
   'The User obviously does not want to join.[/COLOR]
   If Me.Dirty = False Then Exit Sub

   [COLOR="DarkGreen"]'Declare Variables...[/COLOR]
   Dim Ctrl As Control, AFlag As Integer
   
   [COLOR="DarkGreen"]'Enumerate through the frmAddUser Form's Controls and
   'make sure all the TextBoxes have been supplied with
   'data.[/COLOR]
   For Each Ctrl In Me.Controls
      [COLOR="DarkGreen"]'Is the Control we'vr detected a TextBox?[/COLOR]
      If Ctrl.ControlType = acTextBox Then
         [COLOR="DarkGreen"]'It is...good. Is it NULL (contains nothing)?[/COLOR] 
         If IsNull(Ctrl) = True Then
            [COLOR="DarkGreen"]'Yes it contains nothing. Inform User it must be filled in.[/COLOR]
            MsgBox "You must fill in all Form fields to continue!", vbExclamation, _
                   "Incomplete Data Entry"
            [COLOR="DarkGreen"]'Set a Flag to indicate we found a field with no data for later use.[/COLOR]
            AFlag = 1
            [COLOR="DarkGreen"]'Gracefully exit the For/Next loop[/COLOR]
            Exit For
         End If
      End If
   [COLOR="DarkGreen"]'All so far is well...Check the next Control in the frmAddUser Form.[/COLOR]
   Next Ctrl
   
   [COLOR="DarkGreen"]'The Flag is set indicating we have a empty TextBox. So we set
   'the Unload event's Cancel property to TRUE which prevents the Form
   'from closeing. We then set focus onto the empty TextBox so that 
   'it's ready for data entry and then we exit this sub so as not to
   'run the remaining code.[/COLOR]
   If AFlag = 1 then Cancel = True: Ctrl.SetFocus: Exit Sub

   [COLOR="DarkGreen"]'If we get to this point, everything is well. All the TextBoxes are
   'filled in so let's attach the Name the User supplied to the frmStartUp
   'Form's Tag property so that we can use it as show in the LanCheck
   'function.[/COLOR]
   Forms("frmStartUp").Tag = Me.Employee_Name
End Sub

(not tested)

Hope this helps. Good luck with your project.

.
 

Users who are viewing this thread

Back
Top Bottom