Scroll records in main form - ignore linked subform records

S

smithy

Hi ,
I have a sales order database in Accesss 2007. For each order there can be
1->many line items. I have a main form showing order details & a subform
showning the item details. I want to add a scroll button on the main form to
get the next order, but all i get is the next line item, this is okay when
there is only one but a problem if there are 99 items.
Here is the code associated with the control
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Orders"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms![Orders].SetFocus
DoCmd.GoToRecord , , acNext

Thanks for any help.
 
A

Allen Browne

You need to explicitly give some other control on the main form the focus.

Presumably this code is in the event handler for a control in the subform,
so the code would look something like this:

If Me.Dirty Then Me.Dirty = False
With Me.Parent
If .Dirty Then .Dirty = False
If Not .NewRecord Then
![SomeControl].SetFocus
RunCommand acCmdRecordsGotoNew
End If
End With
 
S

smithy

Thanks Allen,

This nearly works but instead of taking me to the next Order, it opens the
form ready to enter a new order.

Allen Browne said:
You need to explicitly give some other control on the main form the focus.

Presumably this code is in the event handler for a control in the subform,
so the code would look something like this:

If Me.Dirty Then Me.Dirty = False
With Me.Parent
If .Dirty Then .Dirty = False
If Not .NewRecord Then
![SomeControl].SetFocus
RunCommand acCmdRecordsGotoNew
End If
End With

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

smithy said:
Hi ,
I have a sales order database in Accesss 2007. For each order there can be
1->many line items. I have a main form showing order details & a subform
showning the item details. I want to add a scroll button on the main form
to
get the next order, but all i get is the next line item, this is okay when
there is only one but a problem if there are 99 items.
Here is the code associated with the control
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Orders"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms![Orders].SetFocus
DoCmd.GoToRecord , , acNext

Thanks for any help.
 
A

Allen Browne

Replace:
acCmdRecordsGotoNew
with:
acCmdRecordsGotoNext

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

smithy said:
Thanks Allen,

This nearly works but instead of taking me to the next Order, it opens the
form ready to enter a new order.

Allen Browne said:
You need to explicitly give some other control on the main form the
focus.

Presumably this code is in the event handler for a control in the
subform,
so the code would look something like this:

If Me.Dirty Then Me.Dirty = False
With Me.Parent
If .Dirty Then .Dirty = False
If Not .NewRecord Then
![SomeControl].SetFocus
RunCommand acCmdRecordsGotoNew
End If
End With

smithy said:
Hi ,
I have a sales order database in Accesss 2007. For each order there can
be
1->many line items. I have a main form showing order details & a
subform
showning the item details. I want to add a scroll button on the main
form
to
get the next order, but all i get is the next line item, this is okay
when
there is only one but a problem if there are 99 items.
Here is the code associated with the control
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Orders"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms![Orders].SetFocus
DoCmd.GoToRecord , , acNext
 

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