|
-
Oct 19th, 2005, 10:28 AM
#1
Thread Starter
Addicted Member
SQL and VBA
Can someone show me how I can use a SELECT statement from within VBA (in Access). All I want to do is retrieve all of the names from a table and add a specific field from each returned rows into a ComboBox.
e.g.
Perform the query...
SELECT empid, name
FROM employees;
... and then add all 'name' fields from the returned rows to a ComboBox.
Thanks.
Using Visual Studio .NET 2005
-
Oct 19th, 2005, 10:36 AM
#2
Re: SQL and VBA
Here's a sample piece of code that populates Combo1 when the form is opened.
VB Code:
Private Sub Form_Open(Cancel As Integer)
With Me.Combo1
.ColumnCount = 2
.Width = 2440
.ColumnWidths = "0;2440"
.BoundColumn = 1
.RowSource = "SELECT BRAND_ID,BRAND_DESC FROM PH_BRAND"
End With
End Sub
I've used a select from my table, just change the SQL statement to point to your table
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Oct 20th, 2005, 04:09 AM
#3
Thread Starter
Addicted Member
Re: SQL and VBA
Ah, that seems simple enough. Thanks.
Could you also tell me how to do the same, but receive the data as an array of strings? I can't see how I would adapt your example to make it do this...
Using Visual Studio .NET 2005
-
Oct 20th, 2005, 04:55 AM
#4
Re: SQL and VBA
Use ADO and a recordset object.
Search the forums or tutorials online there are loads of examples.
Using the array to fill the combobox might be a problem though in access requires special coding.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|