L
Leo
Does anyone know the correct syntax for referring to a Me.FormField , when
"FormField" is generated by code?
I am building an audit form for our Quality Department with 10 cloned tabs
writing to 10 cloned tables. I saved the ADO code in a class module. However,
instead of calling the code 10 times, I decided to iterate through the form
field name 10 times programmatically.
Below is an example of what I am talking about. I have taken the code hidden
in the module and brought it out into the open.
Some additional factors:
1. The code runs perfectly and updates the recordset if I set the form
references manually instead of through code (i.e. Me.txtName1 instead of
Me.[strNameField]
2. When I turn off the error handling, the debug passes by the table name,
which is being assigned correctly.
3. In the immediate window, “? strNameField†does return “txtName1â€, which
is the control I am referring to.
4. Yet, when I run the code, I get an error message saying that field "|" is
an incorrect reference.
Any suggestions? I hate the thought of writing the Add code 10 times … and
the OnCurrent code to display the data 10 times … and the edit saved record
10 times …
Thanks!
Leo
Dim counter as Integer
Dim strFieldNumber as String
Dim strTableName as string
Dim steNameField as String
Dim rst as ADODB.Recordset
Set rst = New ADODB.Recordset
For counter = (1-10)
strFieldNumber = CString (counter)
strTableName = “tblAudit†& strFieldNumber
strNameField = “txtName†& strFieldNumber
With rst
.Connection = CurrentProject.Connection
.Open, “SELECT * from “ & TableName “;â€
.AddNew
!Name = Me.[strNameField]
.Update
.Close
End With
Set rst = Nothing
Exit Sub
"FormField" is generated by code?
I am building an audit form for our Quality Department with 10 cloned tabs
writing to 10 cloned tables. I saved the ADO code in a class module. However,
instead of calling the code 10 times, I decided to iterate through the form
field name 10 times programmatically.
Below is an example of what I am talking about. I have taken the code hidden
in the module and brought it out into the open.
Some additional factors:
1. The code runs perfectly and updates the recordset if I set the form
references manually instead of through code (i.e. Me.txtName1 instead of
Me.[strNameField]
2. When I turn off the error handling, the debug passes by the table name,
which is being assigned correctly.
3. In the immediate window, “? strNameField†does return “txtName1â€, which
is the control I am referring to.
4. Yet, when I run the code, I get an error message saying that field "|" is
an incorrect reference.
Any suggestions? I hate the thought of writing the Add code 10 times … and
the OnCurrent code to display the data 10 times … and the edit saved record
10 times …
Thanks!
Leo
Dim counter as Integer
Dim strFieldNumber as String
Dim strTableName as string
Dim steNameField as String
Dim rst as ADODB.Recordset
Set rst = New ADODB.Recordset
For counter = (1-10)
strFieldNumber = CString (counter)
strTableName = “tblAudit†& strFieldNumber
strNameField = “txtName†& strFieldNumber
With rst
.Connection = CurrentProject.Connection
.Open, “SELECT * from “ & TableName “;â€
.AddNew
!Name = Me.[strNameField]
.Update
.Close
End With
Set rst = Nothing
Exit Sub