473,465 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Populate combo box items from database

52 New Member
Hi, im using vb6 and access, im using combo box in my form. I want to retrieve the items for combo box automatically from database. Plzzzzzz help me , urgent. Thanks.
Apr 11 '08 #1
4 4924
debasisdas
8,127 Recognized Expert Expert
Kindly post the code that you are working on.
Apr 11 '08 #2
vaniKanabathy
52 New Member
Expand|Select|Wrap|Line Numbers
  1. Dim myconn As ADODB.Connection
  2. 'Declares strSQL as a string for the SQL statement
  3. Dim strSQL As String
  4.  
  5. db_file = App.Path
  6.     If Right$(db_file, 1) <> "\" Then db_file = db_file & "\"
  7.     db_file = db_file & "Everspark2.mdb"
  8.  
  9. 'Sets myconn as a connection
  10. Set myconn = New ADODB.Connection
  11. myconn.ConnectionString = _
  12.         "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  13.         "Data Source=" & db_file & ";" & _
  14.         "Persist Security Info=False"
  15.     myconn.Open
  16.  
  17.  Combo1.Clear
  18.  
  19.  
  20.      Dim rsRecords As New ADODB.Recordset
  21.      Set rsRecords = New ADODB.Recordset
  22.      Dim sSQL As String
  23.      sSQL = "SELECT CarType FROM CarList"
  24.      rsRecords.Open sSQL, myconn
  25.  
  26.     With rsRecords
  27.     .Open CarList, myconn
  28.     Do While Not .EOF
  29.     Combo1.AddItem .Fields("CarType")
  30.         .MoveNext
  31.     Loop
  32.  
  33.     Combo1.AddItem
  34.     .Close
  35.  
  36.     End With
  37.     Set rsRecords = Nothing
Apr 11 '08 #3
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

You have already opened the recordset, again why open...?
check the modified code here :

Expand|Select|Wrap|Line Numbers
  1. With rsRecords
  2. ' Comment the Line Below
  3. '.Open CarList, myconn
  4.  
  5. Do While Not .EOF
  6. Combo1.AddItem .Fields("CarType")
  7. .MoveNext
  8. Loop
  9.  
  10.  
REgards
Veena
Apr 11 '08 #4
vaniKanabathy
52 New Member
I get the solution.Thanks.

Expand|Select|Wrap|Line Numbers
  1. db_file = App.Path
  2.     If Right$(db_file, 1) <> "\" Then db_file = db_file & "\"
  3.     db_file = db_file & "Everspark2.mdb"
  4.  
  5.     ' Open a connection.
  6.     Set conn = New ADODB.Connection
  7.     conn.ConnectionString = _
  8.         "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  9.         "Data Source=" & db_file & ";" & _
  10.         "Persist Security Info=False"
  11.     conn.Open
  12.  
  13.     ' Select the data.
  14.     statement = "SELECT CarType FROM CarList "
  15.  
  16.     ' Get the records.
  17.     Set rs = conn.Execute(statement, , adCmdText)
  18.  
  19. With Combo1
  20. Do Until rs.EOF
  21. .AddItem rs.Fields("CarType").Value
  22. rs.MoveNext
  23. Loop
  24. End With
  25.  rs.Close
  26.     conn.Close
Apr 11 '08 #5

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

Similar topics

2
by: portroe | last post by:
in VB. net how do you populate a combobox with items? thanks portroe
3
by: Sampson | last post by:
I have a question about enumeration and how to populate them during runtime. I am using vb.net but will happily take any advice in c# as well. Here is an example to help illustrate what I am...
2
by: Dave McKie | last post by:
Hi all I am trying to Populate a combo box from a selection in an adjacent Listview. The Listview lists as a string the field names of 4 different fields in tblFile. So far I can populate the...
2
by: TS | last post by:
Hi all, From my windows form, I opened a connection to a SQL database. Now I need to generate a combo box from a SELECT statement pointing to the last name column in the SQL tables. I am stuck...
16
by: agrawal.solutions | last post by:
Hello Friends I am asking a very silly question but i dont find any solution fo this.. I am selectiong a recordset and want to populate a combobox where id would be inviseble and the content...
7
by: nareshpulipati | last post by:
Hi all, I am new to VB .net. Iam trying to populate the database item into combo box. Database Type:SQL(ODBC) My code retuns no value in combo box Public Class Form1 Private Sub...
1
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, I've a column in a dataGridView set as combobox. I can't find any example showing how to populate the list in the combobox. Does anyone have an example showing me this. Regards Jesper.
5
by: giandeo | last post by:
Hello Experts. Could you find a solution for this problem please! I have the following tables in Access Database Table Name: origin Fields Names: country, countrycode Table Name: make...
4
by: baasu | last post by:
i want to populate a combo box with items in the table of my access database. i ve seen some code on the internet but wasnt able to understand dem much.pls help!
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.