Brock, Christian T, HRC-Alexandria
Christian.Brock at hoffman.army.mil
Thu Apr 1 09:22:22 CST 2004
Why go to the trouble? From the statement of intent, What the user really wants is a duplicate current record button, instead of a new record button. The Access XP command button wizard will allow you to create a button that will duplicate the current record. It creates the following lines of code DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append Obviously MS did not update the wizard to use readable code. The following will work as well. DoCmd.RunCommand acCmdSelectRecord DoCmd.RunCommand acCmdCopy DoCmd.RunCommand acCmdPasteAppend Christian Brock -----Original Message----- From: Gustav Brock [mailto:gustav at cactus.dk] Sent: Thursday, 01 April 2004 09:36 To: Access Developers discussion and problem solving Subject: Re: [AccessD] Add new record + fill fields with last entered data? Hi Tina > I begin to understand. At the OnCurrent Event for the Form, the Event > Procedure will set the DefaultValue of each TextBox to the values > determined to already be stored in the record just saved. Is that > correct? Yes and no. No saving needs to take place: At the OnCurrent Event for the Form, the Event Procedure will set the DefaultValue of each TextBox (or ComboBox etc.) to the values for the current record of those controls. > Does this require explicitly listing each TextBox of the form? Yes. /gustav >>>How does one set the DefautlValue at OnCurrent? I don't know how to do >>>that. >> >>That's not difficult - something like this: >> >> Dim txt As TextBox >> Set txt = Me!txtYourTextBox >> >> txt.DefaultValue = txt.Value >> >> Set txt = Nothing >> >>However, DefaultValue should be a string which means that if your >>textbox contains decimals or a date/time value you must be careful and >>convert to a string in US format: >> >> txt.DefaultValue = LTrim(Str(txt.Value)) >> >>or >> >> txt.DefaultValue = _ >> Format(txt.Value, "\#mm\/dd\/yyyy hh\:nn\:ss AM/PM\#") >> >>/gustav >> >>>>Tough day? No coffee? >>>> >>>>Set the DefaultValue at OnCurrent. >>>> >>>>As for Stuart's note on the KeyPreview, it's not a user feature, but a >>>>property of the form. >>>> >>>>/gustav >>>> >>>>>when a user clicks the 'Add new record' button (s)he wants the data of the current record to be displayed in the new record. >>>>>So if a user is on record 999 with field username filled with AAA and then clicks on 'Add new record' then a new record (1000) must appear with the field username filled with AAA. -- _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com