Syntax question for Forms collection 
Author Message
 Syntax question for Forms collection

I am going through the fields of a recordset and I'm trying to get the
value of the same fields in the form but Access is reading my temporary
variable name as one that should be in the form.

My code looks like:

Dim te As Form
Dim vrecord As Recordset
Dim fName As String

For Each fValue In vrecord.Fields
        Debug.Print "field name: " & fValue.Name
        Debug.Print "field value: " & fValue.Value
        fName = fValue.Name
        Debug.Print "te value: " & te!fName
Next

I'd like the last line to print the value that is stored in the field
referenced by fName but Access is expecting fName to be a field name in
the form.  Is there syntax that I can use the make Access read the value
in fName rather than think it's an actual field name?

TIA
Bob



Tue, 19 Feb 2002 03:00:00 GMT  
 Syntax question for Forms collection
If I am reading your question correctly you want to retrieve the field
name(s) and value(s) for the current record on a form?

Private sub SomeCommandButton_click()
Dim rst as recordset
Dim intFieldCount as Integer
Dim i as Integer

Set rst = me.recordsetclone

If me.Dirty = true Then Me.Dirty = false

With rst
    .Bookmark = Me.Bookmark
    intFieldCount = .Fields.count
    For i = 0 To intFieldCount - 1
        Debug.print "field name: " & .Fields(i).name
        Debug.print "field value: " & .Fields(i).value
    next i
end with

Set rst = nothing

end sub
--
Doug
Reply to is anti-spammed remove the "z" from email

Quote:

>I am going through the fields of a recordset and I'm trying to get the
>value of the same fields in the form but Access is reading my temporary
>variable name as one that should be in the form.

>My code looks like:

>Dim te As Form
>Dim vrecord As Recordset
>Dim fName As String

>For Each fValue In vrecord.Fields
>        Debug.Print "field name: " & fValue.Name
>        Debug.Print "field value: " & fValue.Value
>        fName = fValue.Name
>        Debug.Print "te value: " & te!fName
>Next

>I'd like the last line to print the value that is stored in the field
>referenced by fName but Access is expecting fName to be a field name in
>the form.  Is there syntax that I can use the make Access read the value
>in fName rather than think it's an actual field name?

>TIA
>Bob



Tue, 19 Feb 2002 03:00:00 GMT  
 Syntax question for Forms collection
I am not quite sure about your question, but you neet to set the objects you
have dimed, this ought to get you started////

Sub...
dim db as database
Dim te as recordset
dim fName as field

set db = currentdb
set te = db.openrecordset("table or query")
set fName = ts("NameofField")

    do until te.eof
        debug.print fname.name & " "  & fname.value
        rs.movenext
    loop

Quote:

>I am going through the fields of a recordset and I'm trying to get the
>value of the same fields in the form but Access is reading my temporary
>variable name as one that should be in the form.

>My code looks like:

>Dim te As Form
>Dim vrecord As Recordset
>Dim fName As String

>For Each fValue In vrecord.Fields
>        Debug.Print "field name: " & fValue.Name
>        Debug.Print "field value: " & fValue.Value
>        fName = fValue.Name
>        Debug.Print "te value: " & te!fName
>Next

>I'd like the last line to print the value that is stored in the field
>referenced by fName but Access is expecting fName to be a field name in
>the form.  Is there syntax that I can use the make Access read the value
>in fName rather than think it's an actual field name?

>TIA
>Bob



Wed, 20 Feb 2002 03:00:00 GMT  
 Syntax question for Forms collection
The recordsetclone method will work as mentioned, but if that isn't what you
are trying to accomplish, you refer to the CONTROLS on a form with:
Me.Controls("controlname")
What typically happens is that the control and field have the same name,
unless you put the control on the form and then assign the bound field to
it.   The Me.Controls notation can also take an index value starting at 0,
but that loops through all labels as well   I typically use unbound forms
and bind data in code using loops as follows

I = 0
For Each Ctl in Me.Controls
    If Ctl.ControlType = acTextBox Then
        rs!Field(I) = Ctl.Value
        I = I + 1
    End If
Next



Quote:
> I am going through the fields of a recordset and I'm trying to get the
> value of the same fields in the form but Access is reading my temporary
> variable name as one that should be in the form.

> My code looks like:

> Dim te As Form
> Dim vrecord As Recordset
> Dim fName As String

> For Each fValue In vrecord.Fields
>         Debug.Print "field name: " & fValue.Name
>         Debug.Print "field value: " & fValue.Value
>         fName = fValue.Name
>         Debug.Print "te value: " & te!fName
> Next

> I'd like the last line to print the value that is stored in the field
> referenced by fName but Access is expecting fName to be a field name in
> the form.  Is there syntax that I can use the make Access read the value
> in fName rather than think it's an actual field name?

> TIA
> Bob



Thu, 21 Feb 2002 03:00:00 GMT  
 Syntax question for Forms collection
Thank you, guys, but I don't think I explained myself quite good enough.  I've
got two nearly identical tables, call them TABLE_A and TABLE_B (TABLE_B is a
subset of the items in TABLE_A).  I'm on the form for TABLE_A, the control names
on the form are identical to the item names in the table.   On Current of Form_A
a query is generated that retrieves recordset of exactly 1 row from TABLE_B.
Now, what I want to do is go through form_A with the values from the recordset
and identify those values that do not match.  Remember, the TABLE_B recordset is
a subset of the items on the form.

I really appreciate the help.  Hopefully, I've made it clearer.

Bob

Quote:

> > I am going through the fields of a recordset and I'm trying to get the
> > value of the same fields in the form but Access is reading my temporary
> > variable name as one that should be in the form.

> > My code looks like:

> > Dim te As Form
> > Dim vrecord As Recordset
> > Dim fName As String

> > For Each fValue In vrecord.Fields
> >         Debug.Print "field name: " & fValue.Name
> >         Debug.Print "field value: " & fValue.Value
> >         fName = fValue.Name
> >         Debug.Print "te value: " & te!fName
> > Next

> > I'd like the last line to print the value that is stored in the field
> > referenced by fName but Access is expecting fName to be a field name in
> > the form.  Is there syntax that I can use the make Access read the value
> > in fName rather than think it's an actual field name?

> > TIA
> > Bob



Fri, 22 Feb 2002 03:00:00 GMT  
 Syntax question for Forms collection
Bob: use te(fName)
GR
Quote:

> Thank you, guys, but I don't think I explained myself quite good enough.  I've
> got two nearly identical tables, call them TABLE_A and TABLE_B (TABLE_B is a
> subset of the items in TABLE_A).  I'm on the form for TABLE_A, the control names
> on the form are identical to the item names in the table.   On Current of Form_A
> a query is generated that retrieves recordset of exactly 1 row from TABLE_B.
> Now, what I want to do is go through form_A with the values from the recordset
> and identify those values that do not match.  Remember, the TABLE_B recordset is
> a subset of the items on the form.

> I really appreciate the help.  Hopefully, I've made it clearer.

> Bob

> > > I am going through the fields of a recordset and I'm trying to get the
> > > value of the same fields in the form but Access is reading my temporary
> > > variable name as one that should be in the form.

> > > My code looks like:

> > > Dim te As Form
> > > Dim vrecord As Recordset
> > > Dim fName As String

> > > For Each fValue In vrecord.Fields
> > >         Debug.Print "field name: " & fValue.Name
> > >         Debug.Print "field value: " & fValue.Value
> > >         fName = fValue.Name
> > >         Debug.Print "te value: " & te!fName
> > > Next

> > > I'd like the last line to print the value that is stored in the field
> > > referenced by fName but Access is expecting fName to be a field name in
> > > the form.  Is there syntax that I can use the make Access read the value
> > > in fName rather than think it's an actual field name?

> > > TIA
> > > Bob



Fri, 22 Feb 2002 03:00:00 GMT  
 Syntax question for Forms collection
Hi


Quote:
> Thank you, guys, but I don't think I explained myself quite good enough.
I've
> got two nearly identical tables, call them TABLE_A and TABLE_B (TABLE_B is
a
> subset of the items in TABLE_A).  I'm on the form for TABLE_A, the control
names
> on the form are identical to the item names in the table.   On Current of
Form_A
> a query is generated that retrieves recordset of exactly 1 row from
TABLE_B.
> Now, what I want to do is go through form_A with the values from the
recordset
> and identify those values that do not match.  Remember, the TABLE_B
recordset is
> a subset of the items on the form.

> I really appreciate the help.  Hopefully, I've made it clearer.

> Bob

> > > I am going through the fields of a recordset and I'm trying to get the
> > > value of the same fields in the form but Access is reading my
temporary
> > > variable name as one that should be in the form.

> > > My code looks like:

> > > Dim te As Form
> > > Dim vrecord As Recordset
> > > Dim fName As String

> > > For Each fValue In vrecord.Fields
> > >         Debug.Print "field name: " & fValue.Name
> > >         Debug.Print "field value: " & fValue.Value
> > >         fName = fValue.Name
> > >         Debug.Print "te value: " & te!fName
> > > Next

> > > I'd like the last line to print the value that is stored in the field
> > > referenced by fName but Access is expecting fName to be a field name

in

this is because you're using a " !" instead of a " . "!
Try it.

greetings from a mountain



Fri, 22 Feb 2002 03:00:00 GMT  
 Syntax question for Forms collection
I've gotten past this problem now.  Thanks for the help!

Bob



Fri, 22 Feb 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Newbie - Question with ASP Syntax using Request.Form in string

2. syntax question for email form

3. Forms Collection Question

4. Form.Controls collection, another question

5. Urgent question on forms collection

6. Collection.Add and Collection.Item question?

7. Forms Collection: Using it to Open Forms by Passing the Form Name as a String Variable

8. For...Each syntax and object collections - not?

9. Image Collection Syntax - Excel???

10. Sub forms not in the Forms collection?

11. 3rd party generated forms not in Forms collection

12. Hiding forms not in Forms collection

 

 
Powered by phpBB® Forum Software