I want to input username and password SQL Server from userform VBA Excel, but I don't understand how to do that. So I create code like this:
Sub OPenCOnn()
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=SQLOLEDB;Data Source=172.20.20.20;Initial Catalog=bank;User ID=" & txtUser.Text & ";Password=" & txtPass.Text & ";"
End Sub
But its didn't work. I receive the below error:
run time error, object required


Set cnn = New ADODB.Connection?