3

Excel VBA

The following ADO DB Connection string works and fetches data from the database into Excel

Const rspADO As String = "Provider=SQLOLEDB.1;" & _
"Persist Security Info=False;" & _
"Initial Catalog=MyDatabase;" & _
"Data Source=118.aaa.yy.xx;" & _
"User ID=Username;Password=password;"

How do I prompt the user for input of Username and Password (at runtime) using the Data connection prompt (and not the Inputbox or a Userform in Excel)?

Thanks in advance for the help.

1

1 Answer 1

3

If you use the ado db.connection you can according to this vba express post, code extract:

Dim dbConnectStr As String
Set con = New ADODB.Connection

dbConnectStr = "Provider=msdaora;Data Source=" & "Oracle_Database_Name;"

con.ConnectionString = dbConnectStr
con.Properties("Prompt") = adPromptAlways
con.Open dbConnectStr 'ConnectionString

I've also found you may need to set the Prompt property to adPromptComplete.

Sign up to request clarification or add additional context in comments.

1 Comment

As I am trying to connect to an SQL Server, had to change the provider to "Provider=SQLOLEDB.1" in the string above.

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.