Accessing a Sub Form's Data

  • Thread starter Thread starter Trent Argante
  • Start date Start date
T

Trent Argante

How do I iterate throught a sub form's record's &
field's? (I basically want transfer certain fields' data
of all of the sub form's records to a sequential file.)
 
Trent said:
How do I iterate throught a sub form's record's &
field's? (I basically want transfer certain fields' data
of all of the sub form's records to a sequential file.)


Well, you can loop through the (sub)form's RecordsetClone
and write the field values to a text file. From some event
procedure in the main form's module:

Open "pathtofile" For Output Access Write As #1
With Me.subformcontrol.Form.RecordsetClone
Do Until .EOF
Print !fielda, !fieldb, . . .
.MoveNext
Loop
End With
Close #1
 
Marsh,
The provided code basically works with exception to
the .MoveNext method.
It simply returns the first record's data each iteration,
as if the .MoveNext method is not being called.
Trent
 
Are you sure it the first record? Reviewing it, I see that
I forgot to use MoveFirst before the loop, so, if you're
only getting one record in the output, it should be the last
record in the subform:

With Me.subformcontrol.Form.RecordsetClone
.MoveFirst
Do Until .EOF

OTOH, maybe you're not using DAO and whatever the recordset
is, it doesn't support the MoveNext method???
 
Ok, the iteration amount equals the record amount. It may
well be the last record, since my sub form sorts, the
displayed first record may be the last record entered.
Let's assume this and dismiss the DAO aspect for a minute.
If I'm actually getting the last message each iteration,
what would be the cause? Why on the first iteration would
it print the last record's data?
Good Luck, Marsh =;O)
Trent
[DC.J(244)]
-----Original Message-----
Are you sure it the first record? Reviewing it, I see that
I forgot to use MoveFirst before the loop, so, if you're
only getting one record in the output, it should be the last
record in the subform:

With Me.subformcontrol.Form.RecordsetClone
.MoveFirst
Do Until .EOF

OTOH, maybe you're not using DAO and whatever the recordset
is, it doesn't support the MoveNext method???
--
Marsh
MVP [MS Access]



Trent said:
The provided code basically works with exception to
the .MoveNext method.
It simply returns the first record's data each iteration,
as if the .MoveNext method is not being called.

.
 
I thought that if you were only getting a single record in
the text file it would be the last record, because of the
missing MoveFirst. But, if you're getting the correct
number of records in the text file, then I have to suspect
that there's some other problem in the code you're using.

Please post a copy/paste of the code as it now stands.
 
Marsh, here ya go:
[Procedure]
'Is activated from Click event on main form.
Private Sub cmdTfrSubFormData_Click()
Open "g:\qs9000\mstrlist\tpa_dcj244.dat" For Output As #1
With Me.Item2CPt_SubForm.Form.RecordsetClone
.MoveFirst
Do Until .EOF
Print #1, Item2CPt_SubForm.Form.I2C_Copy,
Item2CPt_SubForm.Form.CPtItemTrackingID,
Item2CPt_SubForm.Form.I2C_PageRng
.MoveNext
Loop
End With
Close
End Sub
[Resulting Text File]
0 983 1
0 983 1
0 983 1
0 983 1
0 983 1
0 983 1

[Text File Should Be]
0 983 1
1 106 1
2 682 1
3 713 1
4 236 1
5 851 1

Trent
DC.J(244)
-----Original Message-----
I thought that if you were only getting a single record in
the text file it would be the last record, because of the
missing MoveFirst. But, if you're getting the correct
number of records in the text file, then I have to suspect
that there's some other problem in the code you're using.

Please post a copy/paste of the code as it now stands.
--
Marsh
MVP [MS Access]



Trent said:
Ok, the iteration amount equals the record amount. It may
well be the last record, since my sub form sorts, the
displayed first record may be the last record entered.
Let's assume this and dismiss the DAO aspect for a minute.
If I'm actually getting the last message each iteration,
what would be the cause? Why on the first iteration would
it print the last record's data?
.
 
Trent said:
Marsh, here ya go:
[Procedure]
'Is activated from Click event on main form.
Private Sub cmdTfrSubFormData_Click()
Open "g:\qs9000\mstrlist\tpa_dcj244.dat" For Output As #1
With Me.Item2CPt_SubForm.Form.RecordsetClone
.MoveFirst
Do Until .EOF
Print #1, Item2CPt_SubForm.Form.I2C_Copy,
Item2CPt_SubForm.Form.CPtItemTrackingID,
Item2CPt_SubForm.Form.I2C_PageRng
.MoveNext
Loop
End With
Close
End Sub


You changed my suggested code to retrieve the values from
the form's controls, which only provides access to the
current record's values. You must get the values from the
fields in the recordset clone. Assuming the control names
are the same as the field names, use this:

Print #1, !I2C_Copy, !CPtItemTrackingID, !I2C_PageRng
 
Marsh,
That did the trick. You're right - I did change the code
because I erronously ignored the bang (!) operator and
originally entered the field names via [I2C_Copy], etc.
But, when that didn't work, I added
the "Item2CPt_SubForm.Form." prefix, which brought me back
to the original problem.
Thank you very much for you help. This upgrade will have
a great impact on my process.
Trent Argante
Document Control Coordinator
Associated Spring
DC.J(244)!Task(93)
-----Original Message-----
Trent said:
Marsh, here ya go:
[Procedure]
'Is activated from Click event on main form.
Private Sub cmdTfrSubFormData_Click()
Open "g:\qs9000\mstrlist\tpa_dcj244.dat" For Output As #1
With Me.Item2CPt_SubForm.Form.RecordsetClone
.MoveFirst
Do Until .EOF
Print #1, Item2CPt_SubForm.Form.I2C_Copy,
Item2CPt_SubForm.Form.CPtItemTrackingID,
Item2CPt_SubForm.Form.I2C_PageRng
.MoveNext
Loop
End With
Close
End Sub


You changed my suggested code to retrieve the values from
the form's controls, which only provides access to the
current record's values. You must get the values from the
fields in the recordset clone. Assuming the control names
are the same as the field names, use this:

Print #1, !I2C_Copy, !CPtItemTrackingID, ! I2C_PageRng
 
Back
Top