tatendatiffany
Board Regular
- Joined
- Mar 27, 2011
- Messages
- 103
I have created a login in vba, I am trying to set it up so when you are logged in already it does take you to the start and force you to login in if you have already logged in before??
any ideas??
this is the login in part of the code
any ideas??
this is the login in part of the code
Code:
Public Function ConnectToDB(username As String, password As String, DatabaseEnv As String) 'recordset'
Range("CredsSaved").Value = "1"
Range("user").Value = username
Range("PWord").Value = password
Range("SaveEnv").Value = DatabaseEnv
Range("CredsSaved,User,PWord,SavedEnv").Font.Color = RGB(255, 255, 255)
If MFcnn.State = 1 Then
MFcnn.Close
End If
On Error GoTo fErr
With MFcnn
.Provider = "IBMDADB2.DB2COPY1"
.Mode = adReadWrite
.ConnectionString = "Password=" & password & ";Persist Security Info=True;User ID=" & username & ";Data Source=" & DatabaseEnv & ";Mode=ReadWrite;"
.Open
If (DatabaseEnv = "") Then
MsgBox "Database name '" & DatabaseEnv & "' is not valid"
End If
End With
If MFcnn.State = 1 Then
ConnectToDB = 0
Login.Hide
End If
'this logs you in and connects you to the databases'
fContinue:
Exit Function
fErr:
Debug.Print Err.Description
MsgBox (Err.Description)
If Err.Number = -2147217843 Then
LoginTries = LoginTries + 1
End If
If LoginTries = 2 Then
ConnectToDB = 2
Else
ConnectToDB = 1
End If
Exit Function
End Function