Test cursor place?

R

Rolf Rosenquist

In an order form I have a button for product search. There is also a
datasheet in a subform.

When the user clicks the button, another form is opened , where he can
search for his product under chosen criterias. When the product is chosen,
the search form is closed and the cursor jumps back to the subform and
inserts all the data for this product. It works fine every time, when the
cursor is standing on the last row for a new record.

But if the cursor stands on an old record, that one will of course be
changed, and that must be prevented.

Is there a way to test if the cursor stands on an old record, or in a row
that is empty in the subform?
/ Rolf
 
A

Allen Browne

This code;
- sets focus back to the original form;
- sets focus to the subform control in that form;
- saves any edits currently in progress in the subform;
- move to a new record if not already there;
- sets the value of the ProdID field to that of the current form;
- closes the current form.


Forms!Form1.SetFocus
Forms!Form1.[Sub1].SetFocus
With Forms!Form1![Sub1].Form
If .Dirty Then
.Dirty = False
End If
If Not .NewRecord Then
RunCommand acCmdRecordsGotoNew
End If
!ProdID = Me.ProdID
End With
DoCmd.Close acForm, Me.Name
 
R

Rolf Rosenquist

Wooow! Here were many useful commands at one session. Very instructive. It
works like a dream!
Many thanks for your help.
/ Rolf




Allen Browne said:
This code;
- sets focus back to the original form;
- sets focus to the subform control in that form;
- saves any edits currently in progress in the subform;
- move to a new record if not already there;
- sets the value of the ProdID field to that of the current form;
- closes the current form.


Forms!Form1.SetFocus
Forms!Form1.[Sub1].SetFocus
With Forms!Form1![Sub1].Form
If .Dirty Then
.Dirty = False
End If
If Not .NewRecord Then
RunCommand acCmdRecordsGotoNew
End If
!ProdID = Me.ProdID
End With
DoCmd.Close acForm, Me.Name


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

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

Rolf Rosenquist said:
In an order form I have a button for product search. There is also a
datasheet in a subform.

When the user clicks the button, another form is opened , where he can
search for his product under chosen criterias. When the product is chosen,
the search form is closed and the cursor jumps back to the subform and
inserts all the data for this product. It works fine every time, when the
cursor is standing on the last row for a new record.

But if the cursor stands on an old record, that one will of course be
changed, and that must be prevented.

Is there a way to test if the cursor stands on an old record, or in a row
that is empty in the subform?
/ Rolf
 

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