new record when form loads

D

Dave Smith

hi,
i'm having trouble finding info on this...

i have a client details form, which has a button to open their "visits"
form. when the form opens i want it to go straight to a blank or new record,
not the first record in the visits table.
if their is some code involved (i'm using access 2000 & 2003) could you
write it in your reply? I am a NOOOB!

also, when the "visits" form opens, the client id returns to "0", forcing me
to manually tupe it in so as to save the record to the correct client... i
want it to stay there!!!

thanks heaps,

dave
 
R

Rick Brandt

Dave said:
hi,
i'm having trouble finding info on this...

i have a client details form, which has a button to open their
"visits" form. when the form opens i want it to go straight to a
blank or new record, not the first record in the visits table.
if their is some code involved (i'm using access 2000 & 2003) could
you write it in your reply? I am a NOOOB!

also, when the "visits" form opens, the client id returns to "0",
forcing me to manually tupe it in so as to save the record to the
correct client... i want it to stay there!!!


Second issue first. When you use an actual subform, meaning a form dispayed
within a subform control that resides on the parent form then propogation of the
linking field (in your case [client id]) is automatic. When you open a separate
form then YOU have to do something to create that propagation.

If the second form will always be used by launching it from the first form then
you can simply set the DefaultValue property of [client id] control to...

Forms!NameOfFirstForm![client id]

If you will sometimes be using the visits form when the clent details form is
not open then you would need to set the DefaultValue property in code. The open
event would be a good place to do this.

As for opening to a new record you have a few options. You can specify
DataEntry mode as an argument of the OpenForm method...

DoCmd.OpenForm "visits",,,, acFormAdd

....or in the Open event of the visits form...

DoCmd.RunCommand acCmdRecordsGoToNew

....or...

DoCmd.OpenForm "visits"
DoCmd.GoToRecord acDataForm, "visits", acNewRec
 
Top