I have decided to put this aside for a while because I have another problem.
I have created a form frmLogin and the code behind this form goes like this:
Private Sub cmdOK_Click()
Dim db As Database
Dim rs As Recordset
Dim teller As Integer
teller = 0
teller = teller + 1
Set db = CurrentDb
Set rs = db.OpenRecordset("select * from tblPaswoord"
If rs.RecordCount > 0 Then
rs.MoveFirst
End If
gebruiker = rs!Gebruikersnaam
Do Until rs.EOF
If rs!Gebruikersnaam = Me!txtGNaam Then
MsgBox "Gebruikersnaam" & vbNewLine & Me!txtGNaam & vbNewLine & "is gevonden", vbInformation, "Gevonden"
If rs!Paswoord = Me!txtPaswoord Then
MsgBox "Paswoord" & vbNewLine & Me!txtPaswoord & vbNewLine & "is gevonden", vbInformation, "Gevonden"
DoCmd.Close acForm, "frmLogin"
DoCmd.OpenForm "frmHoofdmenu"
Exit Do
Else
MsgBox "Paswoord" & vbNewLine & Me!txtPaswoord & vbNewLine & "komt niet overeen met de gebruikersnaam", vbCritical, "Waarschuwing"
teller = teller + 1
Me!txtPaswoord = Null
Me!cmdWissen.SetFocus
Me!txtPaswoord.SetFocus
'Exit Do
End If
Else
'MsgBox "Gebruikersnaam" & vbNewLine & Me!txtGNaam & vbNewLine & "niet gevonden", vbCritical, "Waarschuwing"
Me!txtGNaam = Null
'Me!cmdWissen.SetFocus
Me!txtGNaam.SetFocus
teller = teller + 1
End If
rs.MoveNext
Loop
If teller = 3 Then
MsgBox "Toegang geweigerd!"
DoCmd.Quit acQuitSaveNone
End If
rs.Close
db.Close
End Sub
'If you click the OK button this procedure is being performed, this doesn't appropriately and I can't see the problem.
'Besides this code I have written code behind the textfields :
Private Sub txtGNaam_LostFocus()
If InStr(1, Me.txtGNaam, " ", vbTextCompare) Then
MsgBox "Er mag geen spatie voorkomen in de gebruikersnaam!!", vbInformation
Me.txtGNaam.Value = ""
cmdWissen.SetFocus
txtGNaam.SetFocus
End If
If Trim(txtGNaam.Text) <> "" Then
txtPaswoord.Enabled = True
txtPaswoord.SetFocus
Else
If Trim(txtGNaam.Text) = "" Then
MsgBox "Vul het gebruikersnaam in", vbCritical + vbOKOnly, "Waarschuwing"
cmdWissen.SetFocus
txtGNaam.SetFocus
End If
End If
Me.txtGNaam.Value = StrConv(txtGNaam, vbProperCase)
End Sub
Private Sub txtPaswoord_LostFocus()
If Trim(txtPaswoord.Text) <> "" Then
cmdOK.Enabled = True
cmdOK.SetFocus
Else
If Trim(txtPaswoord.Text) = "" Then
MsgBox "U moet een paswoord intikken", vbCritical + vbOKOnly, "Waarschuwing"
cmdWissen.SetFocus
txtPaswoord.SetFocus
End If
End If
Me.txtPaswoord.Value = StrConv(txtPaswoord, vbUpperCase)
End Sub
'this gives also problems when I want to close this form. It asks me to give up the username because it is empty. The program shouldn't ask me this.
Can you help me with this?
Thank you