use the Form property to refer to a form associated with a subform

A

Ayaz Hoda

When button_1 clicked

it must sets price of specific item in a sub form specific row using
following code
Forms(formA)(formB)!Price.SetFocus

But it always set prices of first row of formB instead of setting price for
3rd or 4th row of sub form

so Is there anyway I can set set focus to
formA > subform (formB) > row (2) in subform

I did find this article but it didn't help to that level

http://msdn.microsoft.com/en-us/library/aa195905(office.11).aspx
 
A

Albert D. Kallal

Ayaz Hoda said:
When button_1 clicked

it must sets price of specific item in a sub form specific row using
following code
Forms(formA)(formB)!Price.SetFocus

But it always set prices of first row of formB instead of setting price
for
3rd or 4th row of sub form

You have to as a rule tell me how you decide it going to be the 3, or 4th
row. As a general rule, you should use the primary key value of a **row** to
define how you are going to update data in a table:

eg:

currentdb.Execute "update tableName set Price = 123 where id = 34433"

You can certainly "move" the sub-form to a particular record, and then
update it that way, but it not the usual approach.

However, here is a code snip to udpate the 4th reocrd price field

Me.MySubFormName.Form.Recordset.AbsolutePosition = 3
me.MySubFormName!price = 123

AbsoultePosition is "zero" based, so in the above, 3 is the 4th reocrd.
 
A

Ayaz Hoda

This subform A is continous form,and display number of purchased items in
sales order.
This subform Ahas price box text field when cursor is at this textbox and
pressing F5, it display another form C which displays price list and user can
pick price from that form by click Paste price. and Price will appear on
subform A price box.
But problem is it always paste price in very first row of continous form
instead of setting price for 2nd or any other row
 
A

Albert D. Kallal

Ayaz Hoda said:
This subform A is continous form,and display number of purchased items in
sales order.
This subform Ahas price box text field when cursor is at this textbox and
pressing F5, it display another form C which displays price list and user
can
pick price from that form by click Paste price. and Price will appear on
subform A price box.
But problem is it always paste price in very first row of continous form
instead of setting price for 2nd or any other row


I got the above.

Did you see/try the two lines of code I posted? It should work and allow you
to update the 4th record as you requested

give that sample code a try, here is the code again:

Me.MySubFormName.Form.Recordset.AbsolutePosition = 3
me.MySubFormName!price = 123

AbsoultePosition is "zero" based, so in the above, 3 is the 4th reocrd.
 
A

Albert D. Kallal

Ayaz Hoda said:
This subform A is continous form,and display number of purchased items in
sales order.
This subform Ahas price box text field when cursor is at this textbox and
pressing F5, it display another form C which displays price list and user
can
pick price from that form by click Paste price. and Price will appear on
subform A price box.
But problem is it always paste price in very first row of continous form
instead of setting price for 2nd or any other row

OK, when you launch that form C, and select the price value, your code to
update the sub-form price value should simply be:


forms!MainFormName!SubFormName!Price = me.Price (from form c).

I assume that form "c" is closed right after the person selects the price.
So, either use the close event of form c, or the after udpate event of the
combo box to "set" the value of price.

Your original request to say that you have to update the fourth record only
who was a bit confusing, and I now understand you simply want to update the
current record that the sub form happens to be on it that point in time when
you launch your view form "c".

The above syntax should allow you to do this, of course if you've got
anything that require ease the sub form, then that's going to mess this up.
on the other hand, there should be no need to read query this sub form
anyway.
 
A

Ayaz Hoda

Hi Albert

I am using following code which is similar to you
but same result

Forms(p)(c)!Price = Format(Me!Price, "#0.00")

Forms(p)(c)!Price.SetFocus

DoCmd.Close acForm, "PriceHelp"

Regards

Ayaz
 
A

Ayaz Hoda

In Access 2007 the F5 key executes a data refresh of the form.

Therefore when you press F5 the currentrecord in the subform is reset due to
the data refresh.

To solve this you need to cancel the data refresh as follows:

Wherever you have the code in for F5

If KeyCode = 116 Then 'Do Something ------------

Replace with

Private Sub Price_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 116 Then
'Do something
KeyCode = 0
End If
 

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