I am working on a macro to pull data from an Oracle DB and return the results back to an excel worksheet. I'm able to connect to the DB when hard coding the credentials. However, I am in need of a solution which will prompt for the user to enter their credentials and validate if the connection is successful, if the credentials are invalid or if the password is, or soon will be, expired. If the connection is anything other than successful, a popup should be displayed indicating the error message. Any help achieving this would be greatly appreciated.
Here is how I'm currently connecting to the DB:
Sub ConnectToOracle()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim mtxData As Variant
Dim oraQuery As String
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open ( _
"User ID=XXXXX" & _
";Password=XXXXX" & _
";Data Source=MBRSTGPTNS" & _
";Provider=OraOLEDB.Oracle")
rs.CursorType = adOpenForwardOnly
'QUERY'
mtxData = rs.GetRows
Worksheets("Sheet1").Activate
ActiveSheet.Range("b1:c1000") = mtxData
Set cn = Nothing
Set rs = Nothing
End Sub