Prompt Login in modify code.

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
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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
You will have to store logged in people ( and allow for recovery after system crash etc) and also have a log off process issued by any closure route ... File/Exit red x on top right alt F4.........
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top