Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Microsoft access question

Thread Tools
 
Search this Thread
 
Old 06 December 2005, 03:39 PM
  #1  
tarmac terror
Scooby Regular
Thread Starter
iTrader: (2)
 
tarmac terror's Avatar
 
Join Date: May 2005
Location: Northern Ireland
Posts: 2,498
Received 0 Likes on 0 Posts
Default Microsoft access question

I have written the following piece of code to extract field names from any table specified by the user.

Function ShowFieldNames(TableName As String)
Dim I As Integer
Dim FieldList As TableDef

Set FieldList = DBEngine(0)(0).TableDefs(TableName)

For I = 0 To FieldList.Fields.Count - 1
'Debug.Print FieldList.Fields(I).Name
Next I
End Function

I would like the list of fields returned to a combo box or list box on a form. Can anyone help. Please Ignore the line in red - this was inserted to return results when debugging in immediate mode. The solution I suspect is staring right at me but I am damned if I can resolve it!!! Am a bit rusty with Access / VBA.

I would reiterate it is the FIELD NAMES I want in the combo box - not the data they contain.

Thanks in advance,
TT
Old 06 December 2005, 04:55 PM
  #2  
Pugster
Scooby Newbie
 
Pugster's Avatar
 
Join Date: Mar 2005
Posts: 13
Likes: 0
Received 0 Likes on 0 Posts
Default

Try this:

Function ShowFieldNames(TableName As String, myCombobox As ComboBox)As Boolean
Dim I As Integer
Dim FieldList As TableDef

Set FieldList = DBEngine(0)(0).TableDefs(TableName)
For I = 0 To FieldList.Fields.Count - 1
myCombobox.AddItem FieldList.Fields(I).Name, I
Next I

If myCombobox.ListCount = 0 Then
ShowFieldNames = False
Else
ShowFieldNames = True
End If
End Function

Call it like this:

If ShowFieldNames("myTable", Me.Combo1) Then
' It updated it
Else
' It didn't update it
End If

This is for a combo box. A list box is similar.
Old 06 December 2005, 08:26 PM
  #3  
tarmac terror
Scooby Regular
Thread Starter
iTrader: (2)
 
tarmac terror's Avatar
 
Join Date: May 2005
Location: Northern Ireland
Posts: 2,498
Received 0 Likes on 0 Posts
Default

Cheers man, found a solution - or should I say was shown the solution. Modify the combo box "record source type" to field names and record source to the name of the table.

Two lines of code - piece of ****. Had to be shown it by a developer with only 6 months experience, who took great pleasure in making me look like a ***....

should point out this is the first time I have worked in Access 2003 - not sure if that makes it better or worse!

thanks again...

TT
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
JimBowen
ICE
5
02 July 2023 01:54 PM
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
TylerD529
General Technical
2
09 October 2015 01:53 AM
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM
Littleted
Computer & Technology Related
4
25 September 2015 09:55 PM



Quick Reply: Microsoft access question



All times are GMT +1. The time now is 06:15 PM.