473,378 Members | 1,549 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,378 software developers and data experts.

The Combo-box with the Database?

I'm using the access database and in my form i have a combo-box for which i need to make a particular field's data appear in its drop-down list..
Say..

I have the "vendorname" field in the table "vendors". Now i need to add all the contents of this field to the combo-box by name say "VenName".

How should i do this! Pls explain?????????????
May 1 '07 #1
8 2121
I'm using the access database and in my form i have a combo-box for which i need to make a particular field's data appear in its drop-down list..
Say..

I have the "vendorname" field in the table "vendors". Now i need to add all the contents of this field to the combo-box by name say "VenName".

How should i do this! Pls explain?????????????
Ok Frnd
it is not so hard. to Populate Data in a Combo.
I am giving U a simple pieces of code to demonstrate how to populate data in combo/list box.
Expand|Select|Wrap|Line Numbers
  1. Dim rsTemp As New ADODB.Recordset
  2.  Dim conTemp As New ADODB.Connection
  3.  
  4.  If rsTemp.State = adStateOpen Then rsTemp.Close
  5.  rsTemp.Open "Select vendorname from vendors ", conTemp, adOpenDynamic, adLockOptimistic
  6.  while rstemp.eof<>true
  7.     combo1.additem rstemp.fields("vendorname").values
  8.     rstemp.movenext
  9.  wend
  10. if combo1.listcount>0 then combo1.listindex=0
  11.  
N.B : I have written this pieces of code in this editor rather than VB IDE. So Some Spelling may be Wrong.Plz Check it carefully.But the moralness concept is same.
May 1 '07 #2
Killer42
8,435 Expert 8TB
If you have a data control on your form, it might be simpler to add the "Microsoft Data Bound List Control" to your project and use the DBCombo control. This allows you to specify the field which provides the dropdown list.
May 1 '07 #3
yeah i actually got this! thnx, but now

I actually i have a vendorid for every vendor in the database! So in my, say purchases form- when the user selects a particular vendor from the combo-box, i want the respected vendorid to appear in the textbox by name say, cvenid.text.

I tried quite a few but as being a newbie to vb i couldn't able get!
So your kind help is needed!

Also i jus wanna know if the way im thinking is preferred in enterprise applications or not? if yu feel anyother ways of doing in a more customized way pls do tell!
May 2 '07 #4
pls do help!!!!!
May 2 '07 #5
Killer42
8,435 Expert 8TB
Sounds as though the simplest thing then might be to use a regular combo box and at startup, create a database connection, read all the vendors and load them into the combobox. (Which is probably what you already said.:))

In the Click or Change event for the Combobox, use another database connection to retrieve the vendor's details and display the ID.

I think you're on the right track.
May 2 '07 #6
thanx for ur advice and as u said, i tried out something like this! Do check this for the error im getting!

Expand|Select|Wrap|Line Numbers
  1. Sub CVenName_Click()
  2. Dim dvenam As Variant
  3. Dim dvenid As Variant
  4. Dim idv As New ADODB.Recordset
  5. Dim idb As New ADODB.Connection
  6.  
  7. dvenam = CVenName.Text
  8. Set idv = New ADODB.Recordset
  9. Set idb = New ADODB.Connection
  10.  
  11. idb.CursorLocation = adUseClient
  12. idb.Open "PROVIDER=Microsoft.jet.OLeDB.3.51;Data Source=" & App.Path & "\GasDb.mdb;"
  13. idv.Open "SELECT VendorId as dvenid from vendors where VendorName='" & dvenam & "'", idb, adOpenDynamic, adLockOptimistic
  14. CVenId.Text = dvenid
  15.  
  16. End Sub
May 2 '07 #7
Killer42
8,435 Expert 8TB
thanx for ur advice and as u said, i tried out something like this! Do check this for the error im getting!

Expand|Select|Wrap|Line Numbers
  1. Sub CVenName_Click()
  2. Dim dvenam As Variant
  3. Dim dvenid As Variant
  4. Dim idv As New ADODB.Recordset
  5. Dim idb As New ADODB.Connection
  6.  
  7. dvenam = CVenName.Text
  8. Set idv = New ADODB.Recordset
  9. Set idb = New ADODB.Connection
  10.  
  11. idb.CursorLocation = adUseClient
  12. idb.Open "PROVIDER=Microsoft.jet.OLeDB.3.51;Data Source=" & App.Path & "\GasDb.mdb;"
  13. idv.Open "SELECT VendorId as dvenid from vendors where VendorName='" & dvenam & "'", idb, adOpenDynamic, adLockOptimistic
  14. CVenId.Text = dvenid
  15.  
  16. End Sub
You didn't way what error you are getting. But I think I see a misconception. You are saying "Select VendorId as dvenid" and then it looks as though you expect the field value to magically appear in the variable of the same name (dvenid). Unless I'm behind the times, there is no connection between the two. All the "AS" clause does is change the field name returned in the query. If you want the field value in a variable, you have to move it there. So your second-last line probably should be something like...
CVenId.Text = idv!dvenid
or
CVenId.Text = idv("dvenid")
In fact, there's probably not much point in renaming the VendorId field at all.
May 2 '07 #8
yeah u were absolutely correct, i made an idiotic expectation there!

thanx for answering my silly things there!!!!!!!!
May 2 '07 #9

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

Similar topics

5
by: Harry Haller | last post by:
<select name="cboPlaces" id="cboPlaces"> <option value="3">Countryside</option> <option value="4">Forest</option> <option value="5">Mountain</option> <option value="6">Desert</option> <option...
1
by: Tina McGibben | last post by:
I basically have a form with a subform with two combo boxes on the main form which filter the subform. The code below works except I cant seem to get it to show all the worksheets when there is...
8
by: bbdata | last post by:
ok i have a problem here and not much time to play round. have a form bound to a table. one of the combos is bound to a field Agents. i have active and retired agents. thing is, i want to be able...
2
by: Al | last post by:
hi,I am using asp.net(vb) I am trying to create 3 combo boxes which are dependable on each other. when comb1 is selected, it shows the comb2 data based on the selection in combo1 and when combo2...
1
by: Alejandro González | last post by:
Hi I have a combobox binded to a Datatable something like combo.DataSource = dt.DefaultView; combo.DisplayMember = "descField"; combo.ValueMember = "valueField"; it works fine.
2
by: G .Net | last post by:
Hi Is there a way to prevent the combo displaying its list of items when the "combo arrow" is clicked? The problem I'm trying to resolve is that depending on a Boolean value, which is set...
8
by: AA Arens | last post by:
Hi I do have a products table and products-parts table in my Access 2003 database and log all services into a form. I do have at least the following two combo boxes on my form: - Choose...
3
by: John | last post by:
AC2007 I changed my combo's row source and then the autocomplete stopped working. The combo is two columns, bound to the first. First column is primary key (ID). Second column is a...
0
by: Jeff | last post by:
I don't remember this being that hard. Or maybe it's just early senility. On a simple bound continuous form I have a combo for filtering the form by customer. The form record source is a sql...
4
by: User | last post by:
Hi people, Excuse if my question is silly, but... i have 2 combo boxes in my project they are binded to fields from same table... one is binded do Code field and another to Description field...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.