473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

loading a combo box from a module

1
Hi all, I am completley new to access/VBA. Trying to find out a way to give the user the option to select list of sql servers/databases by using a combo box on a form. How do I do this? I am using SQL DMO to get a list of all the sql servers/databases but I cant figure out a way to display this in a form..How do I link the form controls to a code in my module so that the combo displays all the servers and the user can select them for the second combo to list all databases..Please help ..

Thanks!
Mar 16 '10 #1
2 2720
NeoPa
32,556 Expert Mod 16PB
I've no idea what SQL DMO is, but if you post what you've got so far we can look at it for you.
Mar 16 '10 #2
ADezii
8,834 Expert 8TB
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.
  1. To populate cboServers with the list of available Servers:
    Expand|Select|Wrap|Line Numbers
    1. Dim i As Integer
    2. Dim oNames As SQLDMO.NameList
    3. Dim oSQLApp As SQLDMO.Application
    4.  
    5. Set oSQLApp = New SQLDMO.Application
    6. Set oNames = oSQLApp.ListAvailableSQLServers()
    7.  
    8. For i = 1 To oNames.Count
    9.   Me![cboServers].AddItem oNames.Item(i)
    10. Next i
  2. 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.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboServers_AfterUpdate()
    2. Dim i As Integer
    3. Dim oSQLServer As New SQLDMO.SQLServer
    4.  
    5. If Not IsNull(Me![cboServers]) Then
    6.   If <UserName> = "" And <Password> = "" Then
    7.     oSQLServer.LoginSecure = True
    8.   End If
    9.  
    10.   oSQLServer.Connect Me![cboServers], "<UserName>", "<Password>"
    11.  
    12.   For i = 1 To oSQLServer.Databases.Count
    13.     With oSQLServer.Databases(i)
    14.       If Not .SystemObject Then
    15.          cboDBs.AddItem .Name
    16.       End If
    17.     End With
    18.   Next i
    19. End If
    20. End Sub
  3. 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>.
Mar 16 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tim Marshall | last post by:
Hi, I'm in the midst of designing a pretty code intensive form that will be the centrepiece of an app I'm working on. It has a very large number of combo boxes (which use pass through queries to...
6
by: CindyH | last post by:
Hi Does anyone know how to create a multi column combo box from the same table? Thanks, Cindy
5
by: jjyconsulting | last post by:
Newbie needing some help. I have a tblParticipants. The fields include gender, education_level, income, occupation etc., I'm trying to create a form where a user can run a query from the form and...
13
by: PW | last post by:
Hi, This is bizarre. I've check and rechecked the spelling, cut and paste the name of the form (when trying to rename the form) and the control yet I still get a parameter prompt when the form...
4
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one...
5
by: Pete Marsh | last post by:
Wondering if anyone can recomend some sample code for dynamically loading the GD module. I have tried setting the extension dir in php.ini, and loading the GD module from there when apache is...
7
by: Rotsey | last post by:
Hi, I am loading a tab control on a form. The code loads textboxes and comboboxes and checkboxes, normal data entry form that loads a table row of data. I have a combo on the form above the...
0
by: dudeja.rajat | last post by:
Hi, I'm using Tkinter module to create a GUI application. I found that the combo box is not present in Tkinter module. It comes with Tix module. Could some one give me an example to create a...
0
by: dudeja.rajat | last post by:
On Mon, Aug 25, 2008 at 12:57 PM, <dudeja.rajat@gmail.comwrote: Ok...now I found the way to do that. But I'm stuck further. my code is as below: main module ********************** myRoot...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.