How to set focus on a new record in a datasheet

D

desgordon

I am creating an application with a parent form and a subform that contains a
datasheet. When a button on the main form is clicked I want to initialize
certain fields on a new record in the datasheet then set the focus to the
next field. I use the following code:

Private Sub NEW_BUILDING_OPTIONS_Click()

HH_Subform.Controls.Item(6).DefaultValue = ""
HH_Subform.Controls.Item(8).DefaultValue = 25
HH_Subform.Controls.Item(10).DefaultValue = 75

HH_Subform.Controls.Item(12).SetFocus

End Sub

The first three lines does what I want it to do i.e. initialize some fields
of a new record to some values I want. The other line however sets the focus
on the correct field, but on the first record of the recordset and not on the
new record as I want.

Can somebody help with this?
 
D

desgordon via AccessMonster.com

I have been able to solve the problem with help from another forum.

For those who may be interested in the solution, the code is:


[HH Subform].SetFocus
DoCmd.GoToRecord , , acNewRec
[HH Subform]![BUILDING_NUMBER] = 1001
[HH Subform]![DWELLING_UNIT_NUMBER] = 2002
[HH Subform]![HOUSEHOLD_NUMBER] = 2002
[HH Subform]![FULL_ADDRESS].SetFocus


Thanks to all who considered helping me.
 

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