Forms.formname.textfield syntax

Zoptooniek

New member
Local time
Today, 15:47
Joined
Jun 22, 2011
Messages
4
Hi Experts,

I am using the forms.formname.fieldname syntax to control fields on a form. However, I have many of these fields and I don't wish to type code for every single one of them.
What I am trying to use is the ampersand to try to concatenate a number to each bit of code so I only need to write it once.

EG - 5 date fileds on the form - txtDate1, txtDate2, txtDate3 etc.....
Say I wanted to disable these fields but on separrate occassions, I don't want to type forms.formname.txtDate1, forms.formname.txtDate2, forms.formname,txtDate3 etc.....

I would like to pull a value from one of my fields also on this form (txtRow) and concatenate this value to the line of code.

EG
Dim Row As String
Row = Forms.formname.txtRow.Value
Forms.formname.txtDate " & Row &" = Date

instead of doing this.....
forms.formname,txtDate1 = Date
forms.formname,txtDate2 = Date
forms.formname,txtDate3 = Date

Is this actually achievable at all??
any help/advice would be greatly appreceated
 
The "controls" (ie textboxes etc) on a form are Items in a Collection. They can be referred to in a For Each Loop. There are vast numbers of way to deal with the processing of the controls both in how they are identified and how they are manipulted. One relatively trivial example:
Code:
Dim ctrl As Control
 
For Each ctrl In Me
 
   Select Case Right(ctrl.name, 1) 
   Case "1"
         ctrl = whatever
   Case "2"
         ctrl = somethingelse
   End Select
 
Next

"Fields" are in the "Recordset" of the Form. The recordset contains the records that result from the RecordSource of the form. The ControlSource "binds" the value in the control to the field in the recordset. It is essentail to realise the difference between controls and fields.

Inside the Form's Class Module the controls and fields can be referred to like this:

Me.somename

Access will first look for a contol called "somename" then a field in the recordset called "somename" if it doesn't find a control and will return the value it holds for the current record.
 

Users who are viewing this thread

Back
Top Bottom