Results 1 to 2 of 2

Thread: If Then Coding?

  1. #1
    Join Date
    Jan 2013
    Posts
    18

    Unanswered: If Then Coding?

    i made a a database and have a table with LanID's. I have a form where people will have to put in a LanID when they first click on the form. i want to make a code using If Then statements. if they put in a correct LanID then the form will open. if they put in wrong LanID. i want a message box to pop up saying something like "invalid LanID, please enter a new one." again i want to do this using IF Then Else statements. if the LanID is correct or not will be based off of the Tables LanID's

    Table Name is NRCEmployees
    Field Name is LanID
    Form name is F_EMPLOYEE

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    This type of thing is normally done with two Forms, a login Form (we'll call it...LogInForm!

    Place an Unbound Textbox on it and name it txtLanID.

    Now, place a Command Button on it and name it cmdSubmitLanID.

    Now use this code behind the Command Button:

    Code:
    Private Static Sub cmdSubmitLanID_Click()
     
    Dim Attempts As Integer
     
     If DCount("*", "NRCEmployees", "[LanID]=" & Me.txtLanID) > 0 Then
      
       DoCmd.OpenForm "F_EMPLOYEE"
       
     Else
      
      MsgBox "Wrong LanID! Please Try Again!", vbCritical, "Warning"
      Attempts = Attempts + 1
      Me.txtLanID.SetFocus
      
      If Attempts = 3 Then
         MsgBox "Login Attempts Have Failed Three Times! Please Contact System Administrator!"
          DoCmd.Close acForm, "LogInForm"
       End If
     
     End If
    
    End Sub


    The code above is correct if LanID is defined as a Number Datatype. If, instead, it is defined as Text, replace

    Code:
    If DCount("*", "NRCEmployees", "[LanID]=" & Me.txtLanID) > 0 Then

    with

    Code:
    If DCount("*", "NRCEmployees", "[LanID]='" & Me.txtLanID & "'") > 0 Then


    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •