Calling subroutine in a subform

G

Guest

Could really use some help on this one...Posted it Thursday evening and
haven't had a response.

I have an A2K form ("ReportsOrder") whose purpose is to change the sequence
in which a group of reports are produced. It's designed similar to the
"References" dialog, showing a list of items and "Up" and "Dn" buttons to
change the order. It contains a continuous subform ("ReportsOrderSubForm")
with record selectors and the report names. The user selects the report in
the subform, then clicks Up or Dn to change its order. Field RptOrder
(integer) holds the order and is used as a sort key.

ReportsOrder is opened as a dialog from another form when a label is clicked:

Private Sub ReportPositionLink_Click()
Me.ParkingSpot.SetFocus
FixOrder = False

'Subform ReportsOrderSubForm generates an error if this is not done.
DoCmd.RunCommand acCmdSaveRecord

DoCmd.OpenForm "ReportsOrder", , , _
"[RptGroup]= '" & Me![RptGroup] & "'", , acDialog
ShowReportOrder
DoCmd.RunCommand acCmdSaveRecord

End Sub

The code to move the report up or down is in the subform:

Private Sub MoveReportDn()
'Can only be called if not last report in list.
Dim myCur As Integer
Dim myNew As Integer
myCur = Me![RptOrder]
DoCmd.GoToRecord , , acNext
myNew = Me![RptOrder]
Me![RptOrder] = myCur
DoCmd.GoToRecord , , acPrevious
Me![RptOrder] = myNew
Me.Requery
Me.RptOrder.SetFocus
DoCmd.FindRecord myNew
Me.CursorPark.SetFocus
End Sub

Private Sub MoveReportUp()
'Can only be called if not first report in list.
Dim myCur As Integer
Dim myNew As Integer
myCur = Me![RptOrder]
DoCmd.GoToRecord , , acPrevious
myNew = Me![RptOrder]
Me![RptOrder] = myCur
DoCmd.GoToRecord , , acNext
Me![RptOrder] = myNew
Me.Requery
Me.RptOrder.SetFocus
DoCmd.FindRecord myNew
Me.CursorPark.SetFocus
End Sub

I call these procedures using the OnClick of two buttons on the parent form:

Private Sub cmdMoveDn_Click()
Me.ParkingSpot.SetFocus
Forms!ReportsOrder![ReportsOrderSubForm].Form.MoveReportDn
End Sub

Private Sub cmdMoveUp_Click()
Me.ParkingSpot.SetFocus
Forms!ReportsOrder![ReportsOrderSubForm].Form.MoveReportUp
End Sub

Problem: When one these button is clicked, I get the following error:
Run-time Error '2465'
Application-defined or object-defined error.

Code compiles without an error. What I've tried:
1) Placed debugging stops in the procedures in the subform, but it never
gets that far.
2) Double-checked the syntax for the call in VBA help ("Call Procedures in a
Subform or Subreport").
3) Placed buttons at the bottom of the subform to call MoveReportUp and
MoveReportDn. It works fine that way.

Would really prefer that buttons be on main form, to right of subform, so
"look" is
consistent with other Windows products.

Anyone know what I'm doing wrong? I'd like to get this cleared up this
weekend if I can.

Thanks,
Bruce
 
B

Bob Hairgrove

[snip]
Anyone know what I'm doing wrong? I'd like to get this cleared up this
weekend if I can.

Try changing the declarations in the subform from Private to Public.
 
G

Guest

Thanks, Bob. I should have caught that one.
Bruce

Bob Hairgrove said:
[snip]
Anyone know what I'm doing wrong? I'd like to get this cleared up this
weekend if I can.

Try changing the declarations in the subform from Private to Public.
 

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