1

I have a datasheet view form. I want to add in it but when i set focus cause of sorting it select the top record which has data in it and edit it. Question is how I can select the new row which has * beside it, so when I set focus it will create a new record.

HOW TO SELECT THE NEW RAW OF A DATASHEET VIEW FORM WITH VBA CODE?

Erik A
  • 31,639
  • 12
  • 42
  • 67
Morteza
  • 344
  • 1
  • 5
  • 16

2 Answers2

1

You can just insert your new record with something like this:

DoCmd.RunSQL("insert into table1 (field1, field2)
    values( " & value1 & ", " & value2 & ")"

(or use parameters, that would be better), then do the SetFocus on your datatsheet.

Rahmani
  • 857
  • 3
  • 14
  • 28
0

Morteza,

By '*' I assume you mean the 'new record' symbol in the record selector box for a new record. If so, let me suggest something simple, and see if it works.

Put this code in the appropriate form or control event handler:

DoCmd.GoToRecord acActiveDataObject, , acNewRec

This should work in any form that has Allow Additions set to Yes.

kismert
  • 1,662
  • 1
  • 13
  • 19
  • Tnx Friend I want to go to last row of current datasheet if I make a new record so it doesn't have the ID of current selection of table, but if go to current new record which has star it has id – Morteza Apr 17 '15 at 19:28
  • _"I want to go to last row of current datasheet if I make a new record so it doesn't have the ID of current selection of table"_ -- The code above will do that if placed in a command button click event. _"but if go to current new record which has star it has id"_ -- I am not following you here. Could you explain further? – kismert Apr 17 '15 at 22:46