TheEntertainer
MIS
Hi,
This probably is fairly simple. but I've got a userform which kicks off on the workbook open event on this is 2 labels into which the user enters their password and username. When they click a command button this is passed to a logon string. This works fine. But what I'm trying to do is anticipate the user putting in the wrong information what I want to do is when the user puts this in on the click of the command button if the connection fails for it to go back to the userform and allow the user to enter again, but I only want this to happen 3 times. Once it fails a 3rd time I want the workbook to close.
Where do I put the code this is the code I'm presently using:
Workbook open()
Private Sub Workbook_Open()
Load UserForm1
UserForm1.StartUpPosition = 2
UserForm1.Show
Private Sub CommandButton1_Click()
sUserid = LCase(TextBox1.Value)
sPassw = LCase(TextBox2.Value)
Dim Application As CRPEAuto.Application
Dim Report As CRPEAuto.Report
Dim CrystalExportOptions As ExportOptions
Dim connectionid
Set Application = CreateObject("Crystal.CRPE.Application"
Dim counter As Integer
If counter > 3 Then Workbooks("Work".Close (False)
On Error Resume Next
connectionid = Application.LogOnServer("pdsodbc.dll", "XXXX", "XXXX", sUserid, sPassw)
If Err.Number = 20536 Then
MsgBox "Incorrect Password and/or User id. You have another " & 3 - counter & " attempts", 48, "WARNING"
Else: UserForm.Show
counter = counter + 1
TextBox1.SetFocus
End If
Next counter
End Sub
I'm using VBA and calling a crystal object which is fine it just the looping of the login which I'm trying to get
Thanks
This probably is fairly simple. but I've got a userform which kicks off on the workbook open event on this is 2 labels into which the user enters their password and username. When they click a command button this is passed to a logon string. This works fine. But what I'm trying to do is anticipate the user putting in the wrong information what I want to do is when the user puts this in on the click of the command button if the connection fails for it to go back to the userform and allow the user to enter again, but I only want this to happen 3 times. Once it fails a 3rd time I want the workbook to close.
Where do I put the code this is the code I'm presently using:
Workbook open()
Private Sub Workbook_Open()
Load UserForm1
UserForm1.StartUpPosition = 2
UserForm1.Show
Private Sub CommandButton1_Click()
sUserid = LCase(TextBox1.Value)
sPassw = LCase(TextBox2.Value)
Dim Application As CRPEAuto.Application
Dim Report As CRPEAuto.Report
Dim CrystalExportOptions As ExportOptions
Dim connectionid
Set Application = CreateObject("Crystal.CRPE.Application"
Dim counter As Integer
If counter > 3 Then Workbooks("Work".Close (False)
On Error Resume Next
connectionid = Application.LogOnServer("pdsodbc.dll", "XXXX", "XXXX", sUserid, sPassw)
If Err.Number = 20536 Then
MsgBox "Incorrect Password and/or User id. You have another " & 3 - counter & " attempts", 48, "WARNING"
Else: UserForm.Show
counter = counter + 1
TextBox1.SetFocus
End If
Next counter
End Sub
I'm using VBA and calling a crystal object which is fine it just the looping of the login which I'm trying to get
Thanks