0

I am relatively new in VBA.

My requirement is to pass UID and PSW in DB2 connection string from the sheet cells. This is the working connection string:

objMyConn.Open "Driver={IBM DB2 ODBC DRIVER};Database=DBName;Hostname=xxx.xxx.xxx;Port=123;Protocol=TCPIP;Uid=" & "XYZ" & ";Pwd=" & "Password"

I want to pass Uid and Pwd from cell A2 and B2 respectively.

Thanks in advance.

1 Answer 1

1

You can declare the passwords as variables and pass them:

Sub TestMe()

    With Worksheets(1)
        Dim pwd As String: pwd = .Range("B2")
        Dim uid As String: uid = .Range("A2")
    End With
    objMyConn.Open "Driver={IBM DB2 ODBC DRIVER};Database=DBName;" & _
        "Hostname=xxx.xxx.xxx;Port=123;Protocol=TCPIP;Uid=" & uid & ";Pwd=" & pwd

End Sub

Thus, before passing the parameters some checks could be carried out:

If IsError(pwd) Then
If Len(pwd) < 6 Then
Sign up to request clarification or add additional context in comments.

1 Comment

For some reason, I am getting invalid credential error, even though the cells contain correct details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.