Full Version: DLookup (loop through filed names)
UtterAccess Forums > Microsoft® Access > Access Forms
Is there a method of looping through field names of a table similar to looping though controls ?
For Each ctl In Me.Controls    
     If InStr(1, ctl.Name, "controlNameHere") > 0 Then
         ctl.visible = True
         End If          
Next ctl
SELECT ProductID, ProductName, UnitPrice FROM Products WHERE CategoryID = 7
    Dim objFields As ADODB.Fields
    objRs.Open strSQL, strConnStr, adOpenForwardOnly, adLockReadOnly, adCmdText
    Set objFields = objRs.Fields
    For intLoop = 0 To (objFields.Count - 1)
        Debug.Print objFields.Item(intLoop).Name
HTH, Steve
Look at this link. Link
actually, my code was untested - i WILL post code that will actually work in a bit...
Dim db As DAO.Database
Dim tdef As DAO.TableDef
Dim fld As DAO.Field
et db = CurrentDb()
For Each tdef In db.TableDefs
If tdef.Name = "Table Name Goes Here" Then
For Each fld In tdef.Fields
Debug.Print fld.Name
Next fld
End If
Next tdef
Set tdef = Nothing
Set db = Nothing
Thanks, everyone, this is what I was looking for.

My code works, but I am trying to populate unbound cascading comboboxes when a user returns to make changes to a record after the record has been saved and the form closed. Since the comboboxes are unbound I created 3 lines of code that looked up the proper record and inserted the data into each of the comboboxes so that the user could see what was selected originally (some of the arrangements have 4 comboboxes working together so if a change is to be made, I will clear the comboboxes and initiate the original cascading set-up) .

However, I just created a query that gets the correct data. This seems like an easier approach. How do I pass the queried data into my comboboxes, since the recordsource for the form is a different query?

Edited by: codedcad on Thu Jun 8 14:50:35 EDT 2006.
Edited by: codedcad on Thu Jun 8 15:03:20 EDT 2006.
You should be able to set the Row Source of the combo box to the query. The form won't care.
Thanks, everybody
I am still haing a problem getting the record data from the query into the combo. I open the query, it gives me the correct data but can't seem to get the correct settings for the combobox. The query has a total of 7 fields. I am trying to get the 4th field data into the combobox. Do I need to set the Bound column, Column count, etc. or should I access the query with a direct SQL statement?
..and, can the query be run in the background, not visible.?
Got it to work using DLookup.
ext, I'm going to try to set the option groups in the same manner.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.