Continuous Subform - Move From Record To Record

M

MikeC

I have a subform that is set to "Continous Forms" view. When I click on a
command button*, I want to cycle through each of the records and concatenate
the displayed values of certain controls to a string variable. Ultimately,
the string variable will be passed to the body of an email.

The problem is that I'm getting an error when I attempt to use the
GoToRecord method of the DoCmd. Because I'm referencing a *subform*, Access
can't see the subform when I reference it by its own name.

The error message is:

"Error #2489 The object "MyForm" isn't open."

Also, I am deliberately trying to avoid using a recordset to collect the
values of the bound fields because several of the controls are combo boxes
and I want to pass column(1), not column(0). I just want to grab the
displayed values of certain controls. Basically, I'm attempting to cycle
through the subform as if it were a recordset.

Code Fragment From Button* Click Event:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Dim i As Integer

'Error occurs on next line.
DoCmd.GoToRecord acDataForm, Me.Name, acFirst
For i = 0 To Me.Recordset.RecordCount
MsgBox Me!cmbLocID.Column(1) 'For test.
'The same error would most likely occur again on the next line if I
could get this far.
DoCmd.GoToRecord acDataForm, Me.Name, acNext
Next i
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

*The above mentioned command button is located in the footer of the subform.

Can anyone tell me whether what I'm attempting to do is possible or if I
need to try something else? Would calling the above code from the main form
instead of the subform make any difference?
 
M

MikeC

Nevermind. I found that the RunCommand method will work in the context
described in my below post. Here's the updated and functioning code
fragment. Now I can just grab the displayed values.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Dim i As Integer

DoCmd.RunCommand acCmdRecordsGoToFirst
For i = 0 To Me.Recordset.RecordCount - 1
MsgBox Me!cmbLocID.Column(1) 'For test.
DoCmd.RunCommand acCmdRecordsGoToNext
Next i
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top