Set focus to New Record

Leesha
BronzeLounger
Posts: 1433
Joined: 05 Feb 2010, 22:25

Set focus to New Record

Post by Leesha »

Hi,
I have sfrmInvoice that is contained in frmInvoice. It is a continuous form. sfrmInvoice is updated from a popup. This is all working fine. I'm would like the focus to be set to [recipeItemName] which is the first textbox in he new record. I've tried doing to this on various events but nothing seems to work. As a result, the user has to click on the cell that that the new info should be placed in. What event would I use to set the foucs to [RecipeItemName] in the new record?
Thanks,
Leesha

User avatar
HansV
Administrator
Posts: 75751
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set focus to New Record

Post by HansV »

Perhaps

Code: Select all

Private Sub Form_Current()
    If Me.NewRecord Then
        Me.RecipeItemName.SetFocus
    End If
End Sub
Regards,
Hans

Leesha
BronzeLounger
Posts: 1433
Joined: 05 Feb 2010, 22:25

Re: Set focus to New Record

Post by Leesha »

I got an error that says ambiguous name detected and points to Form_Current.

User avatar
HansV
Administrator
Posts: 75751
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set focus to New Record

Post by HansV »

You an have only one Form_Current event procedure for a form. Copy the lines

Code: Select all

    If Me.NewRecord Then
        Me.RecipeItemName.SetFocus
    End If
into the other Form_Current procedure (the one you already had), and then delete the entire new Form_Current procedure (the one from my previous reply).
Regards,
Hans

Leesha
BronzeLounger
Posts: 1433
Joined: 05 Feb 2010, 22:25

Re: Set focus to New Record

Post by Leesha »

That took care of the error, however it doesn't move the focus to RecipeItemName in the new row. The new row shows but the record selector remains on the previous row where the data was entered from the popup form.

User avatar
HansV
Administrator
Posts: 75751
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set focus to New Record

Post by HansV »

I'd have to see a copy of the database.
Regards,
Hans