By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

Field Name Count

P: n/a
I want to loop around the field names (fld1 - fld20) in a table
extracting the field name and using it to make changes to the status of
controls(lblFld1 - lblFld20) on a form.

e.g. I would like the code below to make the labels "lblFld1" -
"lblFld20" invisible on a form when the form is opened.

Private Sub Form_Open(Cancel As Integer)

Dim myDb As DAO.Database

Dim myRecs As DAO.Recordset

' Dim i As Integer

Dim fld As DAO.Field

Set myDb = CurrentDb
Set myRecs = myDb.OpenRecordset("tblName", db_Open_Table)
For Each fld In myRecs.Fields
me.controls("lbl" & myrecs.fields.name).visible = false
Next

End Sub

The error coming up says it is having a problem communicating with the
OLE Server or Active X control. There may be a problem evaluating
something or something doesn't exist. Please help as writing code for
each field will most likely cause my hands to drop off.

Thanks you in advance.

May 2 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
mi********@hotmail.com wrote:
I want to loop around the field names (fld1 - fld20) in a table
extracting the field name and using it to make changes to the status of
controls(lblFld1 - lblFld20) on a form.

e.g. I would like the code below to make the labels "lblFld1" -
"lblFld20" invisible on a form when the form is opened.

Private Sub Form_Open(Cancel As Integer)

Dim myDb As DAO.Database

Dim myRecs As DAO.Recordset

' Dim i As Integer

Dim fld As DAO.Field

Set myDb = CurrentDb
Set myRecs = myDb.OpenRecordset("tblName", db_Open_Table)
For Each fld In myRecs.Fields
me.controls("lbl" & myrecs.fields.name).visible = false
Next

End Sub

The error coming up says it is having a problem communicating with the
OLE Server or Active X control. There may be a problem evaluating
something or something doesn't exist. Please help as writing code for
each field will most likely cause my hands to drop off.

Thanks you in advance.


Try:

me.controls("lbl" & fld.name).Properties("Visible") = false

James A. Fortune
CD********@FortuneJames.com

May 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.