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

Populate ComboBox from External Database

194 100+
Hi Everybody, im getting Run-time error '13' Type mismatch on the following code:

cbSNO is a combobox whereas SNO is a text datatype of tbl_MainEntryTable in dbExternal.

Private Sub cboSNO_GotFocus()

With Me![cboSNO]
.RowSourceType = "Value List"
.ColumnCount = 1
.ColumnWidth = -1 'Default Width


End With

Const conPathToExternalDB As String = "C:\dbExternal.mdb"
Dim wrkJet As Workspace, strSQL As String
Dim dbsMain As DAO.Database, rstMain As DAO.Recordset


strSQL = "SELECT DISTINCT tbl_MainEntryTable.SNO FROM tbl_MainEntryTable;"


Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)


Set dbsMain = wrkJet.OpenDatabase(conPathToExternalDB)

Set rstMain = dbsMain.OpenRecordset(strSQL, dbOpenSnapshot)

Do While Not rstMain.EOF
Me![cboSNO].AddItem rstMain![SNO]
rstMain.MoveNext
Loop
rstMain.Close
dbsMain.Close
wrkJet.Close

Set rstMain = Nothing
Set dbsMain = Nothing
Set wrkJet = Nothing

End Sub

Please tell me whats wrong with the code??? its highlighting Me![cboSNO].AddItem rstMain![SNO] in yellow.
Dec 8 '07 #1
6 4494
FishVal
2,653 Expert 2GB
Hi, there.

I'd like to suggest you to use SQL to query external database.
Expand|Select|Wrap|Line Numbers
  1. SELECT ... FROM ... IN <path to external database>;
  2.  
P.S. Your code may fail because RowSourceType of the combobox is not set to value list.
Dec 8 '07 #2
mfaisalwarraich
194 100+
Hi, there.

I'd like to suggest you to use SQL to query external database.
Expand|Select|Wrap|Line Numbers
  1. SELECT ... FROM ... IN <path to external database>;
  2.  
P.S. Your code may fail because RowSourceType of the combobox is not set to value list.
RowSourceType is already set to Value List. The Same code is working on the other field of the table but not on SNO. i failed to understand why? please tell me cuz i wana populate combo box with this particular field. thank u.
Dec 9 '07 #3
FishVal
2,653 Expert 2GB
Hi, there.

Just curious - why don't you want just to set the combobox RowSource to SQL expression quering external database? Like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT tbl_MainEntryTable.SNO FROM tbl_MainEntryTable IN X:\ExternalDataBaseName.mdb;"
  2.  
Dec 9 '07 #4
puppydogbuddy
1,923 Expert 1GB
Hi Everybody, im getting Run-time error '13' Type mismatch on the following code:

cbSNO is a combobox whereas SNO is a text datatype of tbl_MainEntryTable in dbExternal.

Private Sub cboSNO_GotFocus()

With Me![cboSNO]
.RowSourceType = "Value List"
.ColumnCount = 1
.ColumnWidth = -1 'Default Width


End With

Const conPathToExternalDB As String = "C:\dbExternal.mdb"
Dim wrkJet As Workspace, strSQL As String
Dim dbsMain As DAO.Database, rstMain As DAO.Recordset


strSQL = "SELECT DISTINCT tbl_MainEntryTable.SNO FROM tbl_MainEntryTable;"


Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)


Set dbsMain = wrkJet.OpenDatabase(conPathToExternalDB)

Set rstMain = dbsMain.OpenRecordset(strSQL, dbOpenSnapshot)

Do While Not rstMain.EOF
Me![cboSNO].AddItem rstMain![SNO]
rstMain.MoveNext
Loop
rstMain.Close
dbsMain.Close
wrkJet.Close

Set rstMain = Nothing
Set dbsMain = Nothing
Set wrkJet = Nothing

End Sub

Please tell me whats wrong with the code??? its highlighting Me![cboSNO].AddItem rstMain![SNO] in yellow.

Try changing this:
Me![cboSNO].AddItem rstMain![SNO]

To:
rstMain![cboSNO].AddItem rstMain![SNO]
Dec 9 '07 #5
FishVal
2,653 Expert 2GB
Hi, PDB.

I'm almost sure that problem is as indicated - type mismatch.
ComboBox.AddItem method gets string type argument.

Changing
Me![cboSNO].AddItem rstMain![SNO]
to
Me![cboSNO].AddItem "" & rstMain![SNO]

should solve the problem, though I still don't see any reason to populate combobox this way. ;)

Regards,
Fish
Dec 9 '07 #6
puppydogbuddy
1,923 Expert 1GB
Hi, PDB.

I'm almost sure that problem is as indicated - type mismatch.
ComboBox.AddItem method gets string type argument.

Changing
Me![cboSNO].AddItem rstMain![SNO]
to
Me![cboSNO].AddItem "" & rstMain![SNO]

should solve the problem, though I still don't see any reason to populate combobox this way. ;)

Regards,
Fish
Hi Fish,

You are probably right.....I wasn't sure about this, but wanted to give Mohammad something to try. It would be nice if he provided some feedback.

Hi Mohammad,
It would be helpful for other members with a similar problem in the future, if you could update us with the final solution. Thanks.

PDB
Dec 11 '07 #7

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

Similar topics

2
by: James McGivney | last post by:
In a C# program I have an SQL database. A data adapter is connected to the database and a dataset has been generated. I would like to populate a listBox (or comboBox) from the dataset such that...
1
by: Jassim Rahma | last post by:
Hi, what is the best way to populate comboBox from database.. the reason I am asking is that i have more than 8 comboBoxes in one form and each should retrieve data from a table and I don't want...
4
by: Mike L | last post by:
I'm open for any suggestions on how to better program this. I want the user to select a license from a combo box, cboPrivilege and then the user will click the add button, then a record will be...
16
by: Mike Fellows | last post by:
when i load my windows form i populate a combobox i use the code below Dim conn As New System.Data.SqlClient.SqlConnection(strConn) Dim sql As String = "AllLenders" Dim da As New...
0
by: masterej | last post by:
I'm trying to populate a ComboBox (dropdown style) with strings of text from an ArrayList. The ComboBox is actually being populated with the correct items, however, they appear only as blank...
11
by: DSR | last post by:
Help Please... I would like to populate a combo box on a form with a query that compares data from two tables. Any record that is unique in table1 should continue to populate my combobox. The...
5
by: Rich | last post by:
Hello, I have a search application to search data in tables in a database (3 sql server tables). I populate 2 comboboxes with with data from each table. One combobox will contain unique...
1
by: freekedoutfish | last post by:
Hi. New member here Im sat at work, pounding my head off the desk because this tiny bit of simple code refuses to work. The sub is intended to pull data from the "companyname" column in the...
0
by: BenCoo | last post by:
Hello everyone, I'm programming in VB.NET 2005 and I habe not much experience with database programming. I'm in search for some sql for the following : I have 3 database tables:...
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:
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.