Like NeoPa, this is hardly my area of expertise, but you can use the following code as a Template which will hopefully point you in the right direction, at least as far as populating the Combo Boxes. The code makes only 2 assumptions, namely, the Combo Box listing the Servers is named
cboServers, and the Combo Box listing the Databases for each Server selected in cboServers is
cboDBs. Good Luck.
- To populate cboServers with the list of available Servers:
- Dim i As Integer
-
Dim oNames As SQLDMO.NameList
-
Dim oSQLApp As SQLDMO.Application
-
-
Set oSQLApp = New SQLDMO.Application
-
Set oNames = oSQLApp.ListAvailableSQLServers()
-
-
For i = 1 To oNames.Count
-
Me![cboServers].AddItem oNames.Item(i)
-
Next i
- Once a Server is selected, populate cboDBs with the list of Databases residing on the chosen Server. The context of where the code is executed is critical, namely in the AfterUpdate() Event of cboServers.
- Private Sub cboServers_AfterUpdate()
-
Dim i As Integer
-
Dim oSQLServer As New SQLDMO.SQLServer
-
-
If Not IsNull(Me![cboServers]) Then
-
If <UserName> = "" And <Password> = "" Then
-
oSQLServer.LoginSecure = True
-
End If
-
-
oSQLServer.Connect Me![cboServers], "<UserName>", "<Password>"
-
-
For i = 1 To oSQLServer.Databases.Count
-
With oSQLServer.Databases(i)
-
If Not .SystemObject Then
-
cboDBs.AddItem .Name
-
End If
-
End With
-
Next i
-
End If
-
End Sub
- Make the appropriate substitutions for <UserName> and <Password> in Lines 6 and 10. You can actually refer to to Values in Controls (Text Boxes), namely Me![txtUserName] for <UserName>, and Me![txtPassword] for <Password>.