Link to home
Start Free TrialLog in
Avatar of bill201
bill201

asked on

add new record on a other open form with vba on microsoft access 2013

hi

i can two forms open for expamle the names are form1 and form2

and i wan't when i press on some button in form2 it's will set the focus on form1 in a new record by the field form1!Id

something like this

 
        DoCmd.GoToRecord (on form1) , , acNewRec
        DoCmd.GoToControl ("form1!InvoiceNum")
Avatar of MINDSUPERB
MINDSUPERB
Flag of Kuwait image

Hello Bill201,

Try these codes:

DoCmd.GoToRecord acDataForm, "form1", acNewRec
Forms!form1.SetFocus
Forms!form1!InvoiceNum.SetFocus

Sincerely,

Ed
Avatar of bill201
bill201

ASKER

thanks alot for your answer but i get an error message after the first line (it's a sub form so it's look like this :

DoCmd.GoToRecord acDataForm, "Forms!form1parent!form1child.Form", acNewRec

and i get an error message like this "run time error 2489 the object "Forms!form1parent!form1child.Form" isn't open. But the form is actually open, so what is going on there?
ASKER CERTIFIED SOLUTION
Avatar of MINDSUPERB
MINDSUPERB
Flag of Kuwait image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial